vercel/next.js · error · Error

Invalid source: ${matcher.regexp}

Error message

Invalid source: ${matcher.regexp}

What it means

While merging server middleware manifests, TurbopackManifestLoader normalizes matcher regexes that don't start with '^' via tryToParsePath (path-to-regexp); this error is thrown when parsing still fails, meaning a middleware matcher from the Turbopack manifest cannot be converted into a valid anchored RegExp.

Source

Thrown at packages/next/src/shared/lib/turbopack/manifest-loader.ts:819

    if (this.dev && !this.middlewareManifests.takeChanged()) {
      return {
        clientMiddlewareManifestPath,
      }
    }
    const middlewareManifest = this.mergeMiddlewareManifests(
      this.middlewareManifests.values()
    )

    // Server middleware manifest

    // Normalize regexes as it uses path-to-regexp
    for (const key in middlewareManifest.middleware) {
      middlewareManifest.middleware[key].matchers.forEach((matcher) => {
        if (!matcher.regexp.startsWith('^')) {
          const parsedPage = tryToParsePath(matcher.regexp)
          if (parsedPage.error || !parsedPage.regexStr) {
            throw new Error(`Invalid source: ${matcher.regexp}`)
          }
          matcher.regexp = parsedPage.regexStr
        }
      })
    }

    const middlewareManifestPath = join(
      this.distDir,
      'server',
      MIDDLEWARE_MANIFEST
    )
    this.pendingCacheDeletes.push(middlewareManifestPath)
    writeFileAtomic(
      middlewareManifestPath,
      JSON.stringify(middlewareManifest, null, 2)
    )

    // Client middleware manifest This is only used in dev though, packages/next/src/build/index.ts

View on GitHub (pinned to 0eb3775416)

Solutions

  1. Fix the source pattern in the route/rewrite config so it compiles to a valid matcher.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: A redirect/rewrite source fails manifest validation.

Common situations: An invalid matcher regexp in a route manifest entry loaded by Turbopack.


AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19). Data as JSON: /api/errors/9468a839c5ee02c9. Report an issue: GitHub.