Next.js: Error: Invalid middleware found. Capturing groups are not allowed in matcher / `matcher` values must start with `/`
The config.matcher regex in middleware contains an unsupported pattern (capturing group) or invalid syntax.
Capturing groups are not allowed in middleware matcherError: Invalid middleware found. Capturing groups are not allowed`matcher` values must start with `/`Invalid middleware config matcher: Capturing groups are not allowed at`source` must start with / in matcher Meaning
Use non-capturing groups (?:...) and negative lookaheads: /((?!api|_next/static|_next/image|favicon.ico).*). Each matcher string must start with / and be a valid path-to-regexp pattern. Check for stray parentheses and unsupported flags.
Common causes
- Capturing group
(foo|bar)in matcher - Matcher string not starting with
/ - Invalid regex syntax
- Using full regex literal instead of string
- Copy from old Next.js version
⚡ Quick fix
- Use
"/((?!api|_next/static|_next/image|favicon.ico).*)" - Ensure strings start with
/ - Test patterns in the Next.js matcher docs
Detailed fix by platform
Next.js
export const config = { matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"] };
How to diagnose
- Pattern — Capturing groups?
- Prefix — Starts with /?
- Syntax — Valid?
🔧 Still not fixed?
Many errors look alike. If the steps above didn’t solve it, one of these is probably what you’re facing:
Similar errors
- Conflicting app and page file was found Next.js: ⨯ Conflicting app and page file was found, please remove the conflicting files to continue: "pages/index.tsx" - "app/page.tsx"
- Dynamic Code Evaluation not allowed in Edge Runtime Next.js: Dynamic Code Evaluation (e. g. 'eval', 'new Function', 'WebAssembly.compile') not allowed in Edge Runtime
- ERR_TOO_MANY_REDIRECTS (Next.js middleware) Browser: This page isn't working — redirected you too many times (ERR_TOO_MANY_REDIRECTS) with Next.js middleware / trailing slash
Most viewed in Next.js
- NEXT_REDIRECT Next.js: Error: NEXT_REDIRECT (redirect() inside try/catch)
- server-only Next.js: You're importing a component that needs "server-only". That only works in a Server Component
- cookies() should be awaited Next.js 15: Route "/x" used `cookies().get('token')`. `cookies()` should be awaited before using its value
Other ways to find it
Where this error sits
Origin: On your device. Errors that are often confused with or caused by this one (click to open):
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
💬 What worked for others
No tips yet — did something else fix this for you?
Share what worked for you
Tips are checked by an editor before they appear. Links are removed.
Report a correction or suggest an improvement
Last updated 5 Nov 2026