Fix guides · 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.
Common causes – and how to tell which one you have
1. Deprecated middleware file convention
How to tell: Build warns that middleware.ts is deprecated and suggests proxy.ts. The file sits at project root or in src/, not inside /api.
Fix: Rename middleware.ts to proxy.ts and export proxy instead of middleware.
2. Deleted security logic
How to tell: Removing middleware.ts without proxy.ts drops auth/redirect protection for pages.
Fix: Move the same logic into proxy.ts so protections are preserved.
How to fix it
- 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.
Using Lovable, Bolt or 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."
The “fix” to avoid
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.
Copy-paste fix prompt for your AI coding tool
Paste this into Cursor, Claude Code, Lovable or 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.
Questions people ask
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.