The "middleware" file convention is deprecated. Please use "proxy" instead.
Last verified:
The fix
Next.js 16 still runs middleware.ts and prints this warning. The file is now proxy.ts, the export is proxy, and the runtime is Node.js.
- 1
Rename the file and the function
From the directory that contains the file (the project root, or
src/), renamemiddleware.tstoproxy.ts. Changeexport function middlewaretoexport function proxy. Changeexport { auth as middleware }toexport { auth as proxy }. A default export such asexport default clerkMiddleware()can stay a default export. Do not leave a function named onlymiddlewarein the new file. The codemod does this rename:npx @next/codemod@canary middleware-to-proxy .. Read the diff.import { NextResponse } from 'next/server' import type { NextRequest } from 'next/server' export function proxy(request: NextRequest) { return NextResponse.next() } export const config = { matcher: [ '/((?!_next/static|_next/image|favicon.ico|.*\\.(?:svg|png|jpg|jpeg|gif|webp)$).*)', ], } - 2
Remove an Edge runtime line
Delete
export const runtime = 'edge'and anyconfig.runtime. Proxy runs on Node.js. You cannot set it back to Edge. If the snippet uses an Edge-only API and cannot run on Node, keepmiddleware.tsfor now and accept the warning. Do not ship both files. - 3
Delete the old file
After
proxy.tsexists, deletemiddleware.tsin that same folder. Next.js throws if it finds both. A copy insideapp/was never the middleware file. Delete it if a generator added one, so the next edit does not land in the wrong place. - 4
Re-check the auth helper that lived there
Clerk: the file is next to
app/(insidesrc/when you usesrc/), default-exportsclerkMiddleware(), and the matcher still includes the page that callsauth(). Supabase:proxymust callgetUser()and return the response thatsetAllwrote cookies onto. A redirect loop or a missing session after the rename means the new function is not the one that used to refresh the cookie. Config flags rename too:skipMiddlewareUrlNormalizebecomesskipProxyUrlNormalize.
Why it happens
On Next.js 16.4, next dev and next build print this once per process: The "middleware" file convention is deprecated. Please use "proxy" instead. Under it, the log tells you to run npx @next/codemod@canary middleware-to-proxy . and links to middleware-to-proxy. The warning is not a failed request. middleware.ts still runs.
The upgrade guide renames the file to make the network boundary obvious. proxy.ts (or proxy.js) lives in the project root, or in src/ if you use src/, next to app/ or pages/. Not inside app/. The codemod renames the file and the function from middleware to proxy. A default export is still valid. The guide says to rename the function to proxy even when you use a default export. The file exports one function, as the default or as the name proxy.
Rename the file and leave export function middleware, and Next.js 16.4 reports that the file must export a function, either as a default or as a named proxy export, and that you have not updated the exported function. export { auth as middleware } has the same problem until it is export { auth as proxy } or a default export.
The Edge runtime is not supported in proxy. The upgrade guide says the proxy runtime is Node.js and cannot be configured. export const runtime = 'edge' is rejected. Next.js 16.4 says Route segment config is not allowed in Proxy file at "./proxy.ts". Proxy always runs on Node.js runtime. In dev that is logged and forced to Node. A production build throws. Delete the runtime line. If the auth code only works on Edge, keep the deprecated middleware.ts until it can run on Node. The guide says further Edge instructions would come in a later minor.
Both files at once throw: Both middleware file "./middleware.ts" and proxy file "./proxy.ts" are detected. Please use "./proxy.ts" only.
Auth libraries break on the export and the runtime, not on the warning text. Clerk's current Next.js quickstart uses proxy.ts on Next.js 16 and middleware.ts on Next.js 15 and earlier, with the same body: export default clerkMiddleware() and the matcher. A default export survives the rename. If auth() then says it cannot detect clerkMiddleware(), the file is in the wrong folder or the matcher skipped the route. That is a different error.
Supabase session refresh has to be the function Next actually calls. Move getUser() and the setAll cookie copy into export async function proxy, and return the response that received those cookies. A function still named middleware inside proxy.ts never refreshes. The next failure is a missing session or Invalid Refresh Token: Refresh Token Not Found.
skipMiddlewareUrlNormalize in next.config is now skipProxyUrlNormalize. The version 16 codemod updates that flag.
The next error you'll probably hit
Once this is fixed, the usual follow-up is auth() was called but Clerk can't detect usage of clerkMiddleware(). auth() ran on a request that never passed through clerkMiddleware(). The file is in the wrong folder, the matcher skipped the route, or proxy.ts does not export the middleware.
Prompt to paste back into your AI tool
Paste this above the error.
Next.js prints: The "middleware" file convention is deprecated. Please use "proxy" instead. It also says to run npx @next/codemod@canary middleware-to-proxy .
Do not delete the auth check to clear the warning. Do not leave both middleware.ts and proxy.ts. Do not set export const runtime = "edge" in proxy.ts. Do not rename the file and keep export function middleware.
1. Rename middleware.ts to proxy.ts in the project root, or in src/ if this app uses src/. It sits next to app/, not inside app/.
2. Export a function named proxy, or a default export. If the file exports { auth as middleware }, export { auth as proxy }.
3. Remove runtime edge config. Proxy runs on Node.js.
4. If this file calls clerkMiddleware, keep the default export and the matcher. If it refreshes a Supabase session, call getUser() and return the response that received setAll.
5. Delete the old middleware.ts. Change only this file and a renamed config flag.Common questions
+The app still works. Do I have to rename the file?
On Next.js 16 the warning means middleware.ts is deprecated and still runs. Rename it before a future version removes it. Rename it now if the auth library's current docs already generate proxy.ts. Do not keep both files. Next.js throws when it finds middleware.ts and proxy.ts together.
+I renamed the file and Clerk says it can't detect clerkMiddleware(). Why?
The deprecation warning and that Clerk error are different. The warning means the old file was loaded. The Clerk error means clerkMiddleware() did not run for the request. Check that proxy.ts is inside src/ when the app uses src/, that it default-exports clerkMiddleware(), and that the matcher includes the page.
Related errors
- auth() was called but Clerk can't detect usage of clerkMiddleware()auth() ran on a request that never passed through clerkMiddleware(). The file is in the wrong folder, the matcher skipped the route, or proxy.ts does not export the middleware.Cursorv0BoltAuthNext.jsOct 23, 2026
- ERR_TOO_MANY_REDIRECTS on loginERR_TOO_MANY_REDIRECTS on login means the guard and the login page redirect to each other. Exclude the sign-in route and read the session from one place.Cursorv0BoltAuthNext.jsOct 14, 2026
- Auth session missing after refreshAuth session missing: sign-in worked in the browser, but Next.js cannot see the Supabase cookie. Use the @supabase/ssr server client and refresh.CursorLovableBoltSupabaseAuthOct 14, 2026
- Invalid Refresh Token: Refresh Token Not FoundSupabase rejected the refresh token in the cookie. It was already rotated or revoked, or the new token was never written back onto the response.CursorLovableBoltSupabaseAuthOct 23, 2026