nextjs - ✅(Solved) Fix Overly broad patterns during build exceed actual file count [2 pull requests, 1 comments, 2 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#92201Fetched 2026-04-08 02:21:44
View on GitHub
Comments
1
Participants
2
Timeline
6
Reactions
0
Participants
Timeline (top)
cross-referenced ×2commented ×1issue_type_added ×1mentioned ×1

Fix Action

Fixed

PR fix notes

PR #92209: turbopack: avoid duplicate matches for slash-ambiguous patterns

Description (problem / solution / changelog)

What?

  • Deduplicate identical PatternMatch entries returned by read_matches
  • Preserve the earliest match position when collapsing duplicates so result ordering stays stable
  • Add a regression test for slash-ambiguous path.join(...)-style patterns

Why?

path.join(...) can produce multiple slash/no-slash pattern alternatives that resolve to the same real file. read_matches was returning each of those alternatives separately, which inflated the "matches N files" warning.

In the reported case from #92201, 1,000 real files could be reported as 16,000 matches.

How?

  • Make PatternMatch hashable
  • Collect read_matches output into a dedupe map keyed by the final match
  • Keep the lowest alternative index for stable sorting after deduplication
  • Extend test_read_matches to assert the slash-ambiguous pattern only returns unique files

Closes NEXT- Fixes #92201

Changed files

  • turbopack/crates/turbopack-core/src/resolve/pattern.rs (modified, +64/-13)

PR #92234: Turbopack: Include a random sample of matched paths in error messages when TOO_MANY_MATCHES_LIMIT is exceeded

Description (problem / solution / changelog)

This PR is AI generated.

Including sample paths might make it easier to debug or at least triage issues like https://github.com/vercel/next.js/issues/92201

Just seeing the list of patterns might not be enough, because it can be hard to think through how those patterns can map back to real file paths.

Tested with the repro in that PR: <img width="1800" height="532" alt="Screenshot 2026-04-01 at 5 52 16 PM" src="https://github.com/user-attachments/assets/093467ce-61f5-469b-96bb-9ec409264420" />

Changed files

  • Cargo.lock (modified, +1/-0)
  • turbopack/crates/turbopack-ecmascript/Cargo.toml (modified, +1/-0)
  • turbopack/crates/turbopack-ecmascript/src/references/util.rs (modified, +38/-5)

Code Example

git clone https://github.com/remcohaszing/next-issue-broad-patterns.git
cd next-issue-broad-patterns
npm install

---

node script.ts

---

$ npx next build
Next.js 16.2.2 (Turbopack)

  Creating an optimized production build ...
Turbopack build encountered 1 warnings:
./app/page.tsx:14:39
The file pattern ('posts/' <dynamic> '/' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> | 'posts/' <dynamic> | 'posts' <dynamic>) matches 16000 files in [project]/
  12 |         for(const d of await readdir(cDir)) {
  13 |           // results.push(await readFile(`posts/${a}/${b}/${c}/${d}`, 'utf8'))
> 14 |           results.push(await readFile(join('posts', a, b, c, d), 'utf8'))
     |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  15 |         }
  16 |       }
  17 |     }

Overly broad patterns can lead to build performance issues and over bundling.


 Compiled successfully in 3.2s
Finished TypeScript in 1576ms
Collecting page data using 4 workers in 335ms
Generating static pages using 4 workers (3/3) in 471ms
Finalizing page optimization in 9ms

Route (app)
┌ ○ /
└ ○ /_not-found


  (Static)  prerendered as static content

---

Operating System:
  Platform: linux
  Arch: x64
  Version: #202601231045~1769703228~24.04~cb87b5b SMP PREEMPT_DYNAMIC Thu J
  Available memory (MB): 31804
  Available CPU cores: 12
Binaries:
  Node: 24.14.1
  npm: 11.11.0
  Yarn: 1.22.22
  pnpm: 9.14.4
Relevant Packages:
  next: 16.2.2 // Latest available version is detected (16.2.2).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 6.0.2
Next.js Config:
  output: N/A
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/remcohaszing/next-issue-broad-patterns

To Reproduce

Setup:

git clone https://github.com/remcohaszing/next-issue-broad-patterns.git
cd next-issue-broad-patterns
npm install

Generate 1000 files to import dynamically:

node script.ts

Build the Next.js project:

$ npx next build
▲ Next.js 16.2.2 (Turbopack)

  Creating an optimized production build ...
Turbopack build encountered 1 warnings:
./app/page.tsx:14:39
The file pattern ('posts/' <dynamic> '/' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> | 'posts/' <dynamic> '/' <dynamic> | 'posts' <dynamic> '/' <dynamic> | 'posts/' <dynamic> | 'posts' <dynamic>) matches 16000 files in [project]/
  12 |         for(const d of await readdir(cDir)) {
  13 |           // results.push(await readFile(`posts/${a}/${b}/${c}/${d}`, 'utf8'))
> 14 |           results.push(await readFile(join('posts', a, b, c, d), 'utf8'))
     |                                       ^^^^^^^^^^^^^^^^^^^^^^^^^
  15 |         }
  16 |       }
  17 |     }

Overly broad patterns can lead to build performance issues and over bundling.


✓ Compiled successfully in 3.2s
✓ Finished TypeScript in 1576ms
✓ Collecting page data using 4 workers in 335ms
✓ Generating static pages using 4 workers (3/3) in 471ms
✓ Finalizing page optimization in 9ms

Route (app)
┌ ○ /
└ ○ /_not-found


○  (Static)  prerendered as static content

Current vs. Expected behavior

This logs that 16000 files are matched from page.tsx. In reality there are only 1000 that match the pattern.

Commenting line 14 and uncommenting line 13, works around the issue.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #202601231045~1769703228~24.04~cb87b5b SMP PREEMPT_DYNAMIC Thu J
  Available memory (MB): 31804
  Available CPU cores: 12
Binaries:
  Node: 24.14.1
  npm: 11.11.0
  Yarn: 1.22.22
  pnpm: 9.14.4
Relevant Packages:
  next: 16.2.2 // Latest available version is detected (16.2.2).
  eslint-config-next: N/A
  react: 19.2.4
  react-dom: 19.2.4
  typescript: 6.0.2
Next.js Config:
  output: N/A

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

Not sure

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

next build (local), Vercel (Deployed)

Additional context

This looks like a duplicate of #85366, which was marked as solved.

extent analysis

TL;DR

The issue can be fixed by adjusting the file pattern in page.tsx to more accurately match the 1000 files, reducing the overly broad pattern that currently matches 16000 files.

Guidance

  • Review the file pattern in page.tsx and adjust it to be more specific, reducing the number of matched files.
  • Verify the fix by checking the number of matched files during the build process and ensuring it matches the expected 1000 files.
  • Consider commenting out the problematic line and using the workaround mentioned in the issue (uncommenting line 13) to temporarily resolve the issue.
  • Investigate the similarity with issue #85366, which was marked as solved, to see if the solution can be applied to this case.

Notes

The issue seems to be related to an overly broad file pattern in page.tsx, which is causing performance issues and over bundling. Adjusting the pattern to be more specific should resolve the issue.

Recommendation

Apply workaround: Adjust the file pattern in page.tsx to more accurately match the 1000 files, as this is a more targeted solution to the problem and does not rely on upgrading to a potentially non-existent fixed version.

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

nextjs - ✅(Solved) Fix Overly broad patterns during build exceed actual file count [2 pull requests, 1 comments, 2 participants]