-
Notifications
You must be signed in to change notification settings - Fork 29.9k
Description
Link to the code that reproduces this issue
https://github.com/bmamone/vercel-proxy-matcher-issue
To Reproduce
- Start a dev server
- Proxy file's negative matching works (access /login or /api/hello and check for logs. No "request" debug logs)
- Deploy project to Vercel
- Proxy file's negative matching is now ignored and causes redirect errors.
Current vs. Expected behavior
The expected is to not have any "request" debug logs on pages that should be ignored (as configured on proxy's matcher).
The proxy matcher is configured as the docs mention:
export const config = {
matcher: [
'/',
'/((?!api|_next/static|_next/image|login|favicon.ico|sitemap.xml|robots.txt).*)',
],
};
The expected happens when running on a local dev server. But when deployed to Vercel (production or preview) you will see the Proxy (formerly middleware) file being executed on pages that should have been ignored.
In the example project, this causes an infinite redirect loop issue:
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 24.3.0: Thu Jan 2 20:24:06 PST 2025; root:xnu-11215.81.4~3/RELEASE_ARM64_T8103
Available memory (MB): 8192
Available CPU cores: 8
Binaries:
Node: 20.19.5
npm: 10.8.2
Yarn: 1.22.22
pnpm: N/A
Relevant Packages:
next: 16.0.2-canary.23 // Latest available version is detected (16.0.2-canary.23).
eslint-config-next: N/A
react: 19.2.0
react-dom: 19.2.0
typescript: 5.9.3
Next.js Config:
output: N/AWhich area(s) are affected? (Select all that apply)
Middleware, Internationalization (i18n)
Which stage(s) are affected? (Select all that apply)
Vercel (Deployed)
Additional context
The bug happens as soon as i18n is setup on next.config.js and only happens when deployed to Vercel, no matter if production or preview. Could not reproduce the issue in a dev env.
Theres another issue that could be related, but was closed as completed by the original poster.
next.config.js is configured as:
const nextConfig = {
/* config options here */
reactStrictMode: true,
i18n: {
locales: ['en-US', 'pt-BR'],
defaultLocale: 'en-US',
},
};
export default nextConfig;