AI & Agent Dev Bug Sandbox logo
AI & Agent Dev Bug Sandbox
Back to Radar

`Next Build` Shows Generic "Invalid Segment Configuration Export Detected" When `Config.Matcher` Uses `String.Raw` In `Proxy.Ts`

Using `String.raw` in `config.matcher` inside `proxy.ts` triggers a generic build error because Next.js's static analyzer does not evaluate tagged templates, and the error message lacks file and expression details.

mediumConfidence 85%Next.jsApp RouterServer ActionsTurbopackAffected V16.1.3

Origin Analysis

Next.js segment config static analysis requires `config.matcher` to be a literal string or array of literals. `String.raw` is a call expression that is not statically evaluated, so the proxy config is marked invalid, and the error reporter fails to attach the source location or offending expression.
1. Create `src/proxy.ts` with `export const config = { matcher: String.raw`/api/:path*` };` 2. Run `next build` 3. Observe the generic error: `Invalid segment configuration export detected...`

Fixing Code Block

// In packages/next/src/build/segment-config/index.ts // Replace the generic error with a specific one using the AST node location import { codeFrameColumns } from 'next/dist/compiled/babel/code-frame' import { relative } from 'path' export function reportInvalidSegmentConfig( file: { path: string; source: string }, invalidExport: { key: string; loc: { line: number; column: number } } ) { const codeFrame = codeFrameColumns(file.source, { start: invalidExport.loc }, { highlightCode: true }) throw new Error( `Invalid segment configuration export detected in ${relative(process.cwd(), file.path)}.\n` + `The export \`${invalidExport.key}\` must be a static string or array of strings.\n` + `Tagged templates such as \`String.raw\` are not statically analyzable.\n\n` + `${codeFrame}\n\n` + `Please replace \`String.raw\` with a plain string literal (e.g., '/api/:path*').` ) } // Usage: replace the generic throw in collectSegmentConfig with: // const matcherNode = findInvalidMatcher(file, config) // if (matcherNode) reportInvalidSegmentConfig(file, { key: 'matcher', loc: matcherNode.loc })
The hotfix adds a helper that constructs a detailed error message including the file path, a code frame pointing to the invalid export, and an explicit explanation that `String.raw` tagged templates are not statically analyzable. This replaces the generic throw in the segment config collection logic.

Edge Case Audit

This change only affects error reporting; no runtime behavior is altered. Rollback is safe by reverting the diff. Ensure that the `codeFrameColumns` import is available and that the AST location mapping is correctly implemented for the existing parser; otherwise, the error may lack a code frame but still provide the file path. No concurrency or multi-threading issues are introduced.

Ecosystem Topology

Agent Frameworks

LangChain, LlamaIndex, and Pydantic

  1. highProperty graph relation keys collide when entity IDs or labels contain underscores
  2. highCodeActAgent drops assistant tool-call metadata during handoff, leaving an orphan tool response
  3. high[Bug]: HierarchicalNodeParser async methods return the documents unsplit
  4. highLLM.predict_and_call fails with ValidationError for non-function-calling models when react_chat_formatter is omitted
  5. highAnthropic streaming server-tool input_json_delta overwrites completed client tool_use arguments due to stale cur_tool_call state