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

Turbopack Over-Broad Pattern Detection Inflates File Count For Path.Join Dynamic Imports

Next.js 16.2.2 with Turbopack warns that a file pattern matches 16000 files when the actual generated files are only 1000. The warning is caused by Turbopack expanding path.join('posts', a, b, c, d) into a combinatorial glob, leading to possible over-bundling or performance degradation. A simple workaround is to use template literals instead of path.join.

mediumConfidence 85%Next.jsHydrationPages RouterApp RouterAffected V16.2.2

Origin Analysis

Turbopack's dependency tracing treats each argument of path.join as an independent dynamic segment and expands them as a glob pattern across all directory levels, causing combinatorial explosion. It counts all possible paths regardless of actual directory structure, resulting in a false positive over-broad pattern warning (16000 vs 1000).
1. Clone repro repo and run npm install. 2. Run node script.ts to generate 1000 files under posts/. 3. Run npx next build with Turbopack. 4. Observe warning: pattern matches 16000 files, but only 1000 exist.

Fixing Code Block

// app/page.tsx // Replace path.join with template literal to avoid over-broad pattern tracing. // Before: // results.push(await readFile(join('posts', a, b, c, d), 'utf8')) // After: results.push(await readFile(`posts/${a}/${b}/${c}/${d}`, 'utf8'))
Using a template literal produces a single string path, which Turbopack traces more precisely. The path.join call is statically analyzed as a pattern with multiple dynamic segments, each treated as a wildcard, causing the overcount. This workaround resolves the warning and prevents potential over-bundling.

Edge Case Audit

This workaround only solves the symptom for this specific case. If variables contain path separators or unusual characters, a template literal may still be misinterpreted. For the framework fix, Turbopack's tracing should validate patterns against actual files or avoid expanding path.join arguments as glob components. Update should be done in upstream Next.js/Turbopack; no rollback is needed for the user code change, but if the warning persists after an upgrade, revert to path.join if Turbopack has fixed the underlying tracing.

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