Guías de solución · Next.js, Vercel ·

Fix Next.js middleware deprecation - rename middleware.ts to proxy.ts

Next.js middleware is deprecated; use proxy.ts instead

Next.js 16 deprecates middleware.ts in favor of proxy.ts. middleware.ts still works but shows a deprecation warning; it does not fail the build by itself. proxy.ts runs on the Node.js runtime while middleware.ts defaults to Edge. Check for runtime: edge before renaming.

Gratis · 3 al día · sin registro

Causas comunes – y cómo saber cuál es la tuya

1. Deprecated middleware file convention

Cómo saberlo: Build warns that middleware.ts is deprecated and suggests proxy.ts. The file sits at project root or in src/, not inside /api.

Solución: Rename middleware.ts to proxy.ts and export proxy instead of middleware.

2. Deleted security logic

Cómo saberlo: Removing middleware.ts without proxy.ts drops auth/redirect protection for pages.

Solución: Move the same logic into proxy.ts so protections are preserved.

Cómo solucionarlo

  1. Confirm you are on Next.js 16 or later; middleware deprecation appears there.
  2. Locate middleware.ts at the project root or in src/ next to app/.
  3. Check whether the middleware file has an exported config object with runtime set to edge (for example export const config = { runtime: "edge" }), or uses an Edge-only API. proxy.ts runs on the Node.js runtime, so such code must be adapted.
  4. Rename middleware.ts to proxy.ts.
  5. Rename the exported function from middleware to proxy (export { proxy }).
  6. Keep the same auth, redirect, header, and rewrite logic so no protection is removed.
  7. Run next build and confirm the deprecation warning is gone, then test auth/redirects on the moved proxy.

¿Usas Lovable, Bolt o v0?

Tell tool: "Next.js middleware.ts is deprecated in favor of proxy.ts. Rename middleware.ts to proxy.ts, rename exported middleware to proxy, keep all auth/redirect/header logic, run next build, confirm deprecation warning gone. Do not delete middleware without an equivalent proxy.ts."

La “solución” que debes evitar

Do not delete middleware.ts without replacing it — that removes auth/redirect/rewrite protection. Do not move middleware logic into an API route; API routes cannot run before every request the way middleware/proxy does.

Prompt de solución para copiar y pegar en tu herramienta de programación con IA

Pega esto en Cursor, Claude Code, Lovable o Bolt:

My Next.js app warns that middleware.ts is deprecated. Next.js 16 replaces middleware.ts with proxy.ts at the project root or in src/. First check whether middleware.ts has an exported config object with runtime set to edge, or uses Edge-only APIs; proxy.ts runs on the Node.js runtime, so that code must be adapted. Rename middleware.ts to proxy.ts, rename the exported middleware function to proxy, and keep all auth/redirect/header logic so nothing is removed. Then run next build and confirm the deprecation warning is gone. Do not delete middleware.ts without an equivalent proxy.ts.
¿Tu error se ve un poco distinto? Pega tu error exacto y obtén un diagnóstico adaptado a tu código, gratis.

Preguntas frecuentes

Does middleware.ts still work in Next.js 16?

Yes, middleware.ts still works but is deprecated with a warning. Renaming to proxy.ts is the forward-compatible fix.

Where does proxy.ts go?

At the project root or in src/ next to app/, not inside /api or /middleware.

Errores relacionados

Recibe soluciones como esta cada semana