Guias de correção · 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.

Grátis · 3 por dia · sem cadastro

Causas comuns – e como descobrir qual é a sua

1. Deprecated middleware file convention

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

Correção: Rename middleware.ts to proxy.ts and export proxy instead of middleware.

2. Deleted security logic

Como saber: Removing middleware.ts without proxy.ts drops auth/redirect protection for pages.

Correção: Move the same logic into proxy.ts so protections are preserved.

Como corrigir

  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.

Usando Lovable, Bolt ou 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."

A “correção” que você deve 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 correção para copiar e colar na sua ferramenta de IA

Cole isto no Cursor, Claude Code, Lovable ou 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.
Seu erro é um pouco diferente? Cole seu erro exato e receba um diagnóstico sob medida para o seu código — grátis.

Perguntas frequentes

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.

Erros relacionados

Receba correções como esta toda semana