nextjs - ✅(Solved) Fix `next build` shows generic "Invalid segment configuration export detected" when `config.matcher` uses `String.raw` in `proxy.ts` [2 pull requests, 3 comments, 3 participants]

Official PRs (…)
ON THIS PAGE

Recommended Tools

×6

Utilities matched from this issue’s tags and category — try them while you read without losing context.

GitHub issue graph ai analysis

Paste a GitHub issue URL. We fetch that issue, discover linked issues from bodies/comments/timeline, collect linked pull requests, and produce a structured English report.

The report is written in English Markdown for sharing and archival.

Helpful · Quick feedback

Loading…
GitHub stats
vercel/next.js#89937Fetched 2026-04-08 00:21:01
View on GitHub
Comments
3
Participants
3
Timeline
9
Reactions
2
Author
Timeline (top)
commented ×2cross-referenced ×2labeled ×2referenced ×2

Error Message

  1. Observe this error at the end of build:
  • Build fails with a generic segment config error.
  • Error should clearly identify src/proxy.ts and explain that config.matcher must be statically analyzable (or literal), with a specific diagnostic for String.raw.
  • The issue is specifically about error reporting quality: the build failure reason is not pinpointed even though the root cause is String.raw in config.matcher inside proxy.ts.

Root Cause

  • Reproducible locally.
  • The issue is specifically about error reporting quality: the build failure reason is not pinpointed even though the root cause is String.raw in config.matcher inside proxy.ts.

Fix Action

Fixed

PR fix notes

PR #90162: fix: support String.raw tagged templates in segment config extraction

Description (problem / solution / changelog)

Summary

Fixes #89937

When using String.raw in middleware config.matcher:

export const config = {
  matcher: String.raw`/api/:path*`,
}

The build fails with a generic error:

Invalid segment configuration export detected. This can cause unexpected behavior...

Root Cause

extractExportedConstValue in extract-const-value.ts handles TemplateLiteral nodes but not TaggedTemplateExpression nodes. String.raw\...`produces aTaggedTemplateExpression` in the SWC AST.

Fix

  • Add support for TaggedTemplateExpression where the tag is String.raw
  • Return the raw quasis value (preserving backslashes, as String.raw does)
  • Expressions in String.raw templates throw UnsupportedValueError (same as regular templates)
  • Non-String.raw tagged templates throw UnsupportedValueError
  • Added unit tests for all cases

Test Plan

  • Added unit tests for extractExportedConstValue covering:
    • String.raw with simple path patterns
    • String.raw with backslash sequences (preserved as-is)
    • Array with mixed String.raw and string literal elements
    • String.raw with expressions (throws)
    • Non-String.raw tagged templates (throws)

Changed files

  • packages/next/src/build/analysis/extract-const-value.ts (modified, +33/-0)
  • test/unit/extract-const-value.test.ts (added, +58/-0)

PR #91131: fix: include file path in segment config validation error

Description (problem / solution / changelog)

Summary

  • The generic "Invalid segment configuration export detected" error now includes the specific file path that has the issue
  • Added a hint about static analyzability requirements (e.g., String.raw, template literals with variables, function calls are not supported)
  • Added a link to the invalid-page-config docs page for more context

Before:

⨯ Invalid segment configuration export detected. This can cause unexpected behavior from the configs not being applied. You should see the relevant failures in the logs above. Please fix them to continue.

After:

⨯ Invalid segment configuration export detected in "src/proxy.ts". The exported `config` must use statically analyzable values. Dynamic expressions like `String.raw`, template literals with variables, or function calls are not supported.
Read More - https://nextjs.org/docs/messages/invalid-page-config

Fixes #89937

Test plan

  • Updated existing test in test/production/exported-runtimes-value-validation/ to verify the improved error message includes:
    • The "Invalid segment configuration export detected" text
    • The middleware file reference
    • The "statically analyzable" hint

This contribution was developed with AI assistance (Claude Code).

Changed files

  • packages/next/src/build/index.ts (modified, +7/-4)
  • test/production/exported-runtimes-value-validation/index.test.ts (modified, +9/-0)

Code Example

npm install

---

npm run build

---

Invalid segment configuration export detected. This can cause unexpected behavior from the configs not being applied. You should see the relevant failures in the logs above. Please fix them to continue.

---

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0
Binaries:
  Node: 24.11.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.28.1
Relevant Packages:
  next: 16.1.3
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/ahxar/next-proxy-string-raw-repro

To Reproduce

  1. Clone the reproduction repo.
  2. Install dependencies:
    npm install
  3. Run:
    npm run build
  4. Observe this error at the end of build:
    ⨯ Invalid segment configuration export detected. This can cause unexpected behavior from the configs not being applied. You should see the relevant failures in the logs above. Please fix them to continue.
  5. In src/proxy.ts, remove String.raw and use a plain string literal in config.matcher.
  6. Run npm run build again and it succeeds.

Current vs. Expected behavior

Current behavior:

  • Build fails with a generic segment config error.
  • Message says "You should see the relevant failures in the logs above", but there is no actionable failure pointing to src/proxy.ts / config.matcher.

Expected behavior:

  • Error should clearly identify src/proxy.ts and explain that config.matcher must be statically analyzable (or literal), with a specific diagnostic for String.raw.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 25.2.0
Binaries:
  Node: 24.11.1
  npm: 11.6.2
  Yarn: N/A
  pnpm: 10.28.1
Relevant Packages:
  next: 16.1.3
  react: 19.2.3
  react-dom: 19.2.3
  typescript: 5.9.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Middleware

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

  • Reproducible locally.
  • The issue is specifically about error reporting quality: the build failure reason is not pinpointed even though the root cause is String.raw in config.matcher inside proxy.ts.

extent analysis

Fix: Make config.matcher a statically‑analyzable literal

Next.js middleware matcher must be a literal string (or an array of literals) that the compiler can evaluate at build time.
String.raw creates a computed value, so the segment‑config validator throws the generic “Invalid segment configuration export detected” error.

Step‑by‑step

  1. Open src/proxy.ts.

  2. Replace the String.raw call with a plain string (or a template literal that resolves to a literal).

    // BEFORE
    export const config = {
      matcher: String.raw`/api/:path*`,
    };
    // AFTER – simple literal
    export const config = {

Vote matrix · Quick signals

Works
Did the solution work? Tap to confirm.
Easy Fix
Was it a quick fix?
Time Saver
Did it save you time?
Blocking
Was it severely blocking?
Common Issue
Are others likely hitting this too?
Flaky / Intermittent
Is it intermittent?
Verified / Reproducible
Can you reproduce it reliably?
Loading…

Still need to ship something?

×6

Another batch ranked right after the header list — different links, same matching logic.

Back to top recommendations

TRENDING