Fix-Anleitungen · 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.

Kostenlos · 3 pro Tag · ohne Anmeldung

Häufige Ursachen – und woran du erkennst, welche bei dir vorliegt

1. Runtime config in proxy file

So erkennst du es: 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.

Lösung: 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

So erkennst du es: 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.

Lösung: Move the file to project root or src/ next to app/ or pages/ and rename to proxy.ts if needed.

So behebst du ihn

  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.

Du nutzt Lovable, Bolt oder 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.\"

Die „Lösung“, die du vermeiden solltest

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.

Fix-Prompt zum Kopieren für dein KI-Coding-Tool

Füg das in Cursor, Claude Code, Lovable oder Bolt ein:

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.
Dein Fehler sieht etwas anders aus? Füg deinen genauen Fehler ein und bekomm eine auf deinen Code zugeschnittene Diagnose – kostenlos.

Fragen, die oft gestellt werden

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.

Ähnliche Fehler

Bekomm jede Woche Fixes wie diesen