Next.js 16 renames middleware to proxy. Rename the file and the exported function, update renamed config flags, and check you were not relying on the edge runtime.
The short answer
#Rename middleware.ts to proxy.ts, keep it in the same place, and rename the exported function from middleware to proxy. The official codemod does both for you. Your logic, matcher config and NextResponse calls stay the same. The one real change is that proxy always runs on the Node.js runtime, so if you depend on the edge runtime, keep middleware.ts for now.
_10npx @next/codemod@latest middleware-to-proxy .
_10-export function middleware(request: NextRequest) {_10+export function proxy(request: NextRequest) {
Why it happens
#In Next.js 16 the middleware file convention is deprecated and has been renamed to proxy. The Next.js docs give two reasons. The word "middleware" was often confused with Express middleware, which encouraged people to put far too much in it. And "proxy" better describes what the file does: it sits at a network boundary in front of your app and handles a request before it reaches your routes.
The Next.js team also recommends treating proxy as a last resort, and has been adding APIs that cover common uses without it.
The rename comes with a runtime change. Proxy uses the Node.js runtime, and the runtime option cannot be set in a proxy file; setting it throws an error. The edge runtime is not supported in proxy.
How to fix it
#Run the codemod
The middleware-to-proxy codemod renames the file and the named export, and updates config options that contained the word middleware. The general upgrade codemod, npx @next/codemod@canary upgrade latest, includes this step too.
_10npx @next/codemod@latest middleware-to-proxy .
Or rename it by hand
The file goes in the project root, or inside src if you use one, at the same level as app or pages:
_10mv middleware.ts proxy.ts
_14// proxy.ts_14import { NextResponse } from 'next/server';_14import type { NextRequest } from 'next/server';_14_14export function proxy(request: NextRequest) {_14 if (!request.cookies.has('session')) {_14 return NextResponse.redirect(new URL('/login', request.url));_14 }_14 return NextResponse.next();_14}_14_14export const config = {_14 matcher: ['/dashboard/:path*'],_14};
The file must export a single function, either named proxy or as the default export. The docs recommend naming it proxy even when you use a default export.
Rename config flags
Options in next.config.ts that mentioned middleware have new names. For example, skipMiddlewareUrlNormalize is now skipProxyUrlNormalize:
_10// next.config.ts_10import type { NextConfig } from 'next';_10_10const nextConfig: NextConfig = {_10 skipProxyUrlNormalize: true,_10};_10_10export default nextConfig;
The codemod also renames the experimental middlewarePrefetch, middlewareClientMaxBodySize and externalMiddlewareRewritesResolve options to their proxy equivalents.
Remove any runtime setting
If your middleware file exported a runtime value, delete it from proxy.ts. If your code genuinely needs the edge runtime, do not rename the file yet. middleware.ts still works in Next.js 16 while it is deprecated, and the Next.js team has said further edge runtime guidance will follow in a minor release.
Wrap helper functions from libraries
If a library gives you a ready-made middleware function, export it under the new name:
_10// proxy.ts_10import { withAuth } from './lib/with-auth';_10_10export const proxy = withAuth;
Common pitfalls
#- Blindly renaming edge middleware. Check for edge-only code or a
runtimeexport before you switch. - Putting
proxy.tsinsideapp. It must sit besideapp, in the root or insrc. - Leaving the old
middleware.tsin place after creatingproxy.ts. Delete it so there is one clear entry point. - Using proxy as your only auth check. Server Functions are handled as POST requests to the route that uses them, so a matcher change can silently remove coverage. Verify the user inside each Server Function and data access function too.
- Forgetting a
matcher. Without one, proxy runs on every request, including static files and images.
Related reading
#Was this resource helpful?