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.

Free · 3 a day · no signup

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

  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.

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.
Your error looks a bit different? Paste your exact error and get a diagnosis tailored to your code — free.

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.

Related errors

Get fixes like this every week