Fix-Anleitungen · 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.
Häufige Ursachen – und woran du erkennst, welche bei dir vorliegt
1. Deprecated middleware file convention
So erkennst du es: Build warns that middleware.ts is deprecated and suggests proxy.ts. The file sits at project root or in src/, not inside /api.
Lösung: Rename middleware.ts to proxy.ts and export proxy instead of middleware.
2. Deleted security logic
So erkennst du es: Removing middleware.ts without proxy.ts drops auth/redirect protection for pages.
Lösung: Move the same logic into proxy.ts so protections are preserved.
So behebst du ihn
- Confirm you are on Next.js 16 or later; middleware deprecation appears there.
- Locate middleware.ts at the project root or in src/ next to app/.
- 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.
- Rename middleware.ts to proxy.ts.
- Rename the exported function from middleware to proxy (export { proxy }).
- Keep the same auth, redirect, header, and rewrite logic so no protection is removed.
- Run next build and confirm the deprecation warning is gone, then test auth/redirects on the moved proxy.
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 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.
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.