Guias de correção · Next.js, Vercel ·

Fix Next.js 16 proxy files not allowing runtime config

Next.js 16 proxy files do not allow a runtime configuration

Next.js 16 deprecates middleware.ts in favor of proxy.ts. Unlike middleware.ts, proxy files run only on the Node.js runtime — a proxy file cannot set a runtime, and Edge-only middleware must stay as middleware.ts.

Grátis · 3 por dia · sem cadastro

Causas comuns – e como descobrir qual é a sua

1. Runtime config in proxy file

Como saber: Build warns that middleware.ts is deprecated and suggests proxy.ts, but the file contains a 'runtime' configuration object. Proxy files in Next.js 16 run only on the Node.js runtime, so runtime configuration is not allowed.

Correção: If the middleware depends on Edge (runtime: 'edge' or Edge-only APIs), keep the file as middleware.ts. Otherwise, rename middleware.ts to proxy.ts, remove any runtime config, and export a proxy function without runtime settings.

2. Incorrect file location

Como saber: The file is not at the project root or in src/ next to app/ or pages/; proxy files in Next.js 16 must be at project root or src/ directory.

Correção: Move the file to project root or src/ next to app/ or pages/ and rename to proxy.ts if needed.

Como corrigir

  1. Confirm you are on Next.js 16 or later; proxy files run only on the Node.js runtime and cannot set runtime: 'edge'.
  2. Locate the middleware file (e.g., middleware.ts) at the project root or in src/ next to app/.
  3. Check whether the middleware uses Edge-only APIs or exports a config object with runtime: 'edge'.
  4. If it does, keep the file as middleware.ts — Edge still works there — and do not rename it to proxy.ts.
  5. If it does not, rename middleware.ts to proxy.ts, rename the exported function to proxy, and keep all auth/redirect/header logic so protections are preserved.
  6. Run next build and confirm the deprecation warning is gone, then test auth/redirects.

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 shows 'The \"middleware\" file convention is deprecated. Please use \"proxy\" instead.' Next.js 16 removed support for runtime config in proxy files. First check whether the file uses Edge-only APIs or has a 'runtime' config, then keep it as middleware.ts if needed or rename to proxy.ts without runtime settings.
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.

Can I keep middleware.ts if it uses Edge-only APIs?

Yes. Edge-only middleware must stay as middleware.ts; proxy files run only on the Node.js runtime and cannot support Edge-only APIs.

Erros relacionados

Receba correções como esta toda semana