Fix guides · Cursor, Claude Code, v0, Bolt, Windsurf ·
Fix Next.js 16 "middleware file convention is deprecated" (use proxy)
⚠ The "middleware" file convention is deprecated. Please use "proxy" instead.
Next.js 16 renamed middleware to proxy. The warning means your project still has a middleware.ts (or .js) file. It keeps working for now, but you should rename the file to proxy.ts and the exported function from middleware to proxy. Related errors show up when the rename is only half done: both files exist, or proxy.ts still exports a function called middleware.
Common causes – and how to tell which one you have
1. The project still uses middleware.ts
How to tell: You upgraded to Next.js 16 and see the yellow ⚠ warning in the terminal on dev or build. The app still works.
Fix: Run npx @next/codemod@canary middleware-to-proxy . or rename middleware.ts to proxy.ts and the function middleware() to proxy(). The matcher config stays the same.
2. Both middleware.ts and proxy.ts exist
How to tell: The build fails with Both middleware file "./middleware.ts" and proxy file "./proxy.ts" are detected. Please use "./proxy.ts" only. Often an AI created proxy.ts but left the old file.
Fix: Move any logic that only exists in middleware.ts into proxy.ts, then delete middleware.ts.
3. proxy.ts still exports a function called middleware
How to tell: The error says The file "./proxy.ts" must export a function, either as a default export or as a named "proxy" export. The file was renamed, but the function wasn't.
Fix: Rename export function middleware(request) to export function proxy(request), or use export default function proxy(request).
4. proxy.ts sets a runtime
How to tell: The file contains export const runtime = 'edge' (copied from an old middleware example) and the build throws an error about the runtime config.
Fix: Delete the runtime export. Proxy runs on the Node.js runtime, and the runtime option isn't allowed in proxy files.
5. A library or template still expects middleware
How to tell: Auth or i18n libraries (Supabase SSR helpers, next-intl, Clerk, Auth.js) show a middleware.ts example in their docs, and the AI keeps recreating that file.
Fix: Keep the library's code but put it in proxy.ts and call it from a function named proxy. Update the library to a version that supports Next.js 16 if it imports middleware-specific helpers.
How to fix it
- Commit your current state so you can undo the migration if needed.
- Run npx @next/codemod@canary middleware-to-proxy . in the project root. It renames the file and the exported function.
- Check that only proxy.ts (or src/proxy.ts) exists now and middleware.ts is gone.
- Open proxy.ts and make sure it exports a function named proxy (export function proxy(request) {…}) or a default export.
- Remove any export const runtime = 'edge' (or 'nodejs') from proxy.ts. Proxy always runs on the Node.js runtime and doesn't accept the runtime option.
- Rename middleware-named options in next.config, e.g. skipMiddlewareUrlNormalize becomes skipProxyUrlNormalize.
- Restart the dev server and run npm run build to confirm the warning and errors are gone.
Using Lovable, Bolt or v0?
In v0 or Bolt, paste the warning and say: "Rename middleware.ts to proxy.ts, rename the exported function to proxy, delete the old file and keep the matcher and logic exactly the same."
Using Cursor, Claude Code or Windsurf?
Ask Cursor or Claude Code to run the official codemod (npx @next/codemod@canary middleware-to-proxy .) instead of rewriting the file by hand, then run npm run build. Tell it to check for a leftover middleware.ts and a runtime export.
The “fix” to avoid
Agents sometimes downgrade Next.js to 15 to silence the warning, or copy the file so both middleware.ts and proxy.ts exist. The downgrade loses Next.js 16 fixes, and two files break the build. Rename the file and the function instead.
Copy-paste fix prompt for your AI coding tool
Paste this into Cursor, Claude Code, Lovable or Bolt:
Next.js 16 warns: The "middleware" file convention is deprecated. Please use "proxy" instead. Migrate this project to proxy: run npx @next/codemod@canary middleware-to-proxy . or do it by hand. Rename middleware.ts to proxy.ts in the same folder (root or src/), rename the exported function to proxy, keep the config.matcher unchanged, delete the old middleware file, and remove any runtime export from proxy.ts. Rename middleware-named options in next.config (skipMiddlewareUrlNormalize → skipProxyUrlNormalize). Don't change the auth or redirect logic. Run npm run build and show me the diff.
Questions people ask
Is the warning breaking my app?
No. In Next.js 16 middleware.ts still runs. It's deprecated and will be removed in a future version, so migrate now while it's a one-line rename.
Do I need to change my matcher?
No. export const config = { matcher: [...] } works the same in proxy.ts.
Where does proxy.ts go?
In the same place as middleware.ts did: the project root, or src/ if your app uses a src folder. It must sit next to the app or pages folder.
Official documentation
- Next.js: Renaming Middleware to Proxy
- Next.js: proxy.js file convention
- Next.js: Upgrading to version 16