Middleware matcher: Capturing groups are not allowed Next.js Origin: On your device OSI layer 7 · Application Last updated 5 Nov 2026

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.

Exact message you may see 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
Seen on: Next.js

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

  1. Use "/((?!api|_next/static|_next/image|favicon.ico).*)"
  2. Ensure strings start with /
  3. Test patterns in the Next.js matcher docs

Detailed fix by platform

Next.js

  1. export const config = { matcher: ["/((?!api|_next/static|_next/image|favicon.ico).*)"] };

How to diagnose

  1. Pattern — Capturing groups?
  2. Prefix — Starts with /?
  3. 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:

Where this error sits

Origin: On your device. Errors that are often confused with or caused by this one (click to open):

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" (Next.js)Conflicting app and p…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 (Next.js)Dynamic Code Evaluati…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 (Next.js)ERR_TOO_MANY_REDIRECT…Invalid next.config.js options detected — Next.js: Invalid next.config.js options detected: Unrecognized key(s) in object: 'xyz' (Next.js)Invalid next.config.j…next build: fetch failed ECONNREFUSED (build-time API) — Next.js: Error occurred prerendering page "/blog" TypeError: fetch failed { cause: Error: connect ECONNREFUSED 127.0.0.1:3000 } (Next.js)next build: fetch fai…next build: JavaScript heap out of memory — Next.js: FATAL ERROR: Reached heap limit Allocation failed - JavaScript heap out of memory (during next build) (Next.js)next build: JavaScrip…The edge runtime does not support Node.js module — Next.js: The edge runtime does not support Node.js 'crypto' module / A Node.js module is loaded ('fs') which is not supported in the Edge Runtime (Next.js)The edge runtime does…Middlewar…

Explore the map of this error Full error map →

🧠 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.