Next.js proxy.ts: How to Migrate From Middleware in 2026
Next.js 16 deprecates middleware.ts for proxy.ts. Learn the exact rename steps, runtime changes, and gotchas before you run the codemod in 2026.
By Babul Jack
How do I migrate from middleware.ts to proxy.ts in Next.js 16?
Next.js 16 deprecates middleware.ts and replaces it with proxy.ts: a nextjs proxy.ts migration means renaming the file, renaming the exported function from middleware to proxy, and accepting that proxy always runs on the Node.js runtime instead of Edge. The logic inside the function does not change.
I've run this migration on three client codebases since Next.js 16 shipped, and the mechanics are simple. The part that actually breaks things is the runtime change, not the rename. If your middleware used Edge-only APIs or relied on sub-10ms cold starts at a CDN edge node, you need to read past step one before you run the codemod.
The Next.js team gives two reasons for the rename, both stated directly in the official migration docs. First, "middleware" collided with developers' mental model of Express.js middleware, which chains arbitrary server logic — Next.js Middleware was never that. Second, the team wants to discourage overusing the feature: official guidance says to "avoid relying on Middleware unless no other options exist."
The name "proxy" is more literal. It implies a network boundary that sits in front of your app and can run outside your application's main runtime, intercepting a request before it reaches any route. That's a better description of what the file has always done: rewrite, redirect, read or set headers and cookies, or respond directly, before a page or route handler executes.
This is a rename plus a runtime default change, not a new feature. If you've read our Next.js 16 Cache Components migration guide, this is the same release — proxy.ts and Cache Components shipped together, and both show the same pattern: Vercel is making caching and request interception more explicit and less implicit.
Nextjs proxy.ts migration: the exact steps
1. Run the official codemod
The fastest path is the codemod Next.js ships specifically for this rename:
npx @next/codemod@canary middleware-to-proxy .
This renames the file from middleware.ts to proxy.ts and renames the exported function from middleware to proxy. It also updates configuration flags that contained the old name — for example skipMiddlewareUrlNormalize becomes skipProxyUrlNormalize, per the version 16 upgrade guide.
2. Or migrate manually
If you'd rather see every change land in a diff you control:
# Rename your middleware file
mv middleware.ts proxy.ts
// proxy.ts
import { NextResponse } from 'next/server'
import type { NextRequest } from 'next/server'
export function proxy(request: NextRequest) {
return NextResponse.redirect(new URL('/home', request.url))
}
export const config = {
matcher: '/about/:path*',
}
Note the function is renamed even on a default export, and the config.matcher export keeps working exactly as before.
3. Remove any explicit runtime config
In Next.js 15, Middleware could run on the Node.js runtime as a stable opt-in. In 16, Proxy's runtime is fixed to Node.js and cannot be configured — setting runtime: 'nodejs' in a proxy file's config now fails the build. If your old middleware set runtime, delete that line; the codemod removes it automatically.
4. Check Node.js, TypeScript, and browser minimums
Next.js 16 as a whole requires Node.js 20.9+ (LTS) and TypeScript 5.1+; Node 18 is no longer supported. This is unrelated to proxy specifically, but it blocks the upgrade entirely if your CI image is still on an older Node version, per the same upgrade guide. If you're also planning the jump to TypeScript 7 this quarter, line up both migrations — our TypeScript 7 migration guide covers what else breaks.
5. Re-run your matcher tests
Nothing about matcher syntax changed, but proxy still runs on every route by default, including static files and image optimization paths, unless you scope it. This is a good moment to double-check your matcher isn't accidentally blocking _next/static or public/ assets — a classic cause of "my CSS stopped loading after the upgrade" tickets.
Edge runtime vs proxy's Node.js runtime: what actually changes
This is the part most teams skip past, and the part that causes real incidents.
middleware.ts (pre-16)
proxy.ts (16+)
Runtime
Edge runtime (default) or Node.js (stable opt-in since 15.5)
Node.js only, not configurable
Edge runtime support
Yes
No — keep using middleware.ts if you need it
File location
Project root or src/
Same
Exported function name
middleware
proxy
config.matcher
Supported
Unchanged
Deprecation status
Deprecated in 16, still works
Current convention
If your middleware does something genuinely Edge-dependent — ultra-low-latency geolocation redirects served from a CDN point of presence, or logic that must run without touching a regional Node.js server — proxy.ts is not a drop-in replacement yet. Next.js states plainly that middleware.ts "is still available for Edge runtime use cases, but it is deprecated and will be removed in a future version," per the Next.js 16 release notes. There's no committed timeline for removal as of this writing, which gives you a window, not a reprieve.
For most apps — auth redirects, A/B test cookie assignment, locale rewrites, header injection for a reverse proxy pattern — the Node.js runtime is fine and often easier to reason about, since you get full Node APIs instead of the restricted Edge subset.
Common gotchas we hit in client migrations
Auth checks that assumed Edge cold-start speed. If your middleware gated every request through a JWT verification step and you were counting on Edge's near-zero cold start, benchmark proxy.ts under Node.js before rolling out to production traffic. In our tests, Node.js runtime latency was acceptable for session checks but not for extremely chatty paths like static asset gating — exclude those with a matcher instead.
Dynamic matcher values silently ignored. The matcher values must be statically analyzable constants at build time; a variable-driven matcher is silently dropped. This isn't new in 16, but it bites teams migrating because they revisit the file for the first time in months.
revalidateTag() signature change landing in the same release. Next.js 16 also changes revalidateTag() to take a second profile argument for stale-while-revalidate control, and introduces updateTag() for read-your-writes inside Server Actions. If your proxy or route handlers call revalidateTag(), update the call alongside the proxy rename — it's an easy thing to miss in the same upgrade pass, and it's documented in the deprecations table of the 16 release notes.
Turbopack build failures from stray webpack config. Turbopack is now the default bundler for next dev and next build in 16. If any plugin injects a webpack config block you didn't write yourself, next build fails outright to prevent a misconfiguration. Worth checking in the same CI run where you validate the proxy rename, since both are part of the same major-version jump.
If you're carrying a large codebase with multiple middleware files split by route group, our web app development team has handled this exact migration end-to-end for client projects — including benchmarking Node.js vs Edge latency before committing to the rename.
Frequently asked questions
Is middleware.ts actually being removed from Next.js?
Not immediately. Next.js 16 marks middleware.ts as deprecated but keeps it working for Edge runtime use cases. The official docs say it "will be removed in a future version" without a committed date, so plan the migration but don't treat it as urgent-urgent unless you're starting a brand-new project.
Does the proxy.ts rename change my application logic?
No. The function body, request/response handling, NextRequest/NextResponse APIs, cookies, headers, and config.matcher all stay the same. Only the filename, the exported function name, and the fixed Node.js runtime change.
Can I keep using the Edge runtime after upgrading to Next.js 16?
Yes, by keeping the file named middleware.ts instead of renaming it to proxy.ts. You lose nothing immediately, but you're on a deprecated path, and Next.js has said follow-up guidance on continued Edge runtime support is coming in a minor release.
Will the codemod break my existing matcher or header logic?
The codemod only renames the file and the function name, plus a small set of flag names like skipMiddlewareUrlNormalize → skipProxyUrlNormalize. It does not rewrite your matcher patterns or route logic, so existing config.matcher arrays, header manipulation, and redirect logic carry over untouched.
Does proxy.ts run before or after next.config.js redirects?
After headers and redirects from next.config.js, but before filesystem routes and rewrites. This execution order is unchanged from Middleware and is documented in the proxy.js file convention reference.
Key takeaways
Next.js 16 renames middleware.ts to proxy.ts and the exported function from middleware to proxy — run npx @next/codemod@canary middleware-to-proxy . to do it automatically.
Proxy always runs on the Node.js runtime; it cannot be configured to use Edge, so setting runtime: 'nodejs' in its config now fails the build.
middleware.ts still works for Edge-only use cases in 2026 but is deprecated with no committed removal date — don't treat the migration as optional long-term.
Audit your matcher before and after migrating: proxy still runs on every route by default unless scoped, and a loose matcher can block static assets.
The same Next.js 16 release also changes revalidateTag()'s signature and makes Turbopack the default bundler — review both in the same upgrade pass, not just the proxy rename.