Fix guides · Cursor, v0, Claude Code, Bolt ·
Fix Next.js 16 runtime config error in proxy file
Build error about runtime config being rejected in proxy.ts (Next.js 16). The proxy.ts file may contain an export const runtime line that is no longer permitted.
In Next.js 16 the proxy runs only on Node.js and does not accept runtime config in the proxy file. Remove the runtime export from the proxy file. The proxy still runs redirects, rewrites and auth checks. The proxy cannot be replaced by a Route Handler or page segment — those only run for their own paths. After changes, run next build and show me the output proving the error is gone.
Common causes – and how to tell which one you have
1. Leftover runtime export from the old middleware.ts
How to tell: The file was middleware.ts and got renamed to proxy.ts, but export const runtime = 'nodejs' or 'edge' was kept.
Fix: Delete the runtime export line. Next.js 16 sets the proxy runtime itself.
2. An AI added runtime config that isn't valid in proxy
How to tell: You asked the AI to 'use the edge runtime' for the middleware and it added export const runtime = 'edge' to proxy.
Fix: The runtime export must be removed from the proxy file. The proxy runs only on Node.js in Next.js 16. If logic needs Edge runtime, it must run inside the proxy, not in a route handler.
3. Both middleware.ts and proxy.ts exist
How to tell: The project still has middleware.ts alongside proxy.ts, so Next.js 16 throws an error and tells you to keep only proxy.ts.
Fix: Delete middleware.ts and keep only proxy.ts. Make sure the matcher config moved over.
How to fix it
- Find the file: it is named proxy.ts or proxy.js at the project root (or src/), previously middleware.ts. Open it.
- Look for export const runtime = 'nodejs' or export const runtime = 'edge'. Remove that line entirely.
- Remove the runtime export from the proxy file. If the build error flags other exports, remove those too. Keep the proxy function and any config it uses.
- If you moved any logic out of the proxy, verify protected routes still redirect unauthenticated requests.
- Run next build and confirm the build error is gone.
- Delete the old middleware file. Next.js 16 throws an error when both middleware and proxy files exist and tells you to keep only proxy.ts.
Using Lovable, Bolt or v0?
In Cursor or v0, tell the AI: "Next.js 16 renamed middleware to proxy and no longer allows export const runtime in the proxy file. Remove the runtime export from proxy.ts and delete the old middleware.ts. If edge-only logic is needed, move it into a route handler. Then run next build and show the output."
Using Cursor, Claude Code or Windsurf?
Ask the agent to open proxy.ts and list every export, then remove the unsupported runtime export and any leftover middleware.ts. Have it run next build and paste the output. Don't accept a 'should work' without a passing build.
The “fix” to avoid
Renaming back to middleware.ts brings back the old deprecated approach and Next.js 16 keeps middleware working with a deprecation warning. The error remains unresolved.
Copy-paste fix prompt for your AI coding tool
Paste this into Cursor, Claude Code, Lovable or Bolt:
My Next.js 16 build fails with a build error about runtime config in proxy file. The project has a proxy.ts that exports export const runtime. Remove the runtime export from the proxy file, because Next.js 16 sets the proxy runtime to Node.js. The proxy still runs redirects, rewrites and auth checks. Do not replace proxy logic with Route Handlers or page segments — those only run for their own paths. Delete the old middleware.ts if both exist. Then run next build and show me the output proving the error is gone.
Questions people ask
Where does runtime config go now?
Runtime config is set with export const runtime in route.ts for Route Handlers, and in page.tsx or layout.tsx for page and layout route segments. The proxy file no longer accepts it.
What is proxy in Next.js 16?
It's the renamed middleware. It runs before requests are handled, at the same conceptual point, but the file convention and allowed exports changed.
Can I keep using middleware.ts?
It's deprecated in Next.js 16 and produces a warning. Rename it to proxy.ts and remove the unsupported runtime export.