nextjs - 💡(How to fix) Fix Turbopack debug-build-paths omits Pages Router _document in monorepo externalDir app [1 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#93515Fetched 2026-05-06 06:11:44
View on GitHub
Comments
0
Participants
1
Timeline
2
Reactions
0
Author
Participants
Timeline (top)
labeled ×2

Error Message

unhandledRejection Error [PageNotFoundError]: Cannot find module for page: /_document

Code Example

git clone https://github.com/Stanzilla/next-debug-build-paths-pages-repro.git
cd next-debug-build-paths-pages-repro
npm install
npm run build

---

cd apps/web && next build --debug-build-paths=pages/[gameId]/rank/matchmaking/index.jsx

---

npm run build:canary

---

unhandledRejection Error [PageNotFoundError]: Cannot find module for page: /_document
    at ignore-listed frames {
  type: 'PageNotFoundError',
  code: 'ENOENT'
}

---

Next.js 16.2.4
Next.js 16.3.0-canary.10
React 18.3.1
macOS
Turbopack build
RAW_BUFFERClick to expand / collapse

Link to the code that reproduces this issue

https://github.com/Stanzilla/next-debug-build-paths-pages-repro

To Reproduce

git clone https://github.com/Stanzilla/next-debug-build-paths-pages-repro.git
cd next-debug-build-paths-pages-repro
npm install
npm run build

The build script runs:

cd apps/web && next build --debug-build-paths=pages/[gameId]/rank/matchmaking/index.jsx

This also reproduces with canary:

npm run build:canary

Current vs. Expected behavior

Current behavior:

The selective build compiles successfully, then fails while collecting page data:

unhandledRejection Error [PageNotFoundError]: Cannot find module for page: /_document
    at ignore-listed frames {
  type: 'PageNotFoundError',
  code: 'ENOENT'
}

Expected behavior:

next build --debug-build-paths=pages/[gameId]/rank/matchmaking/index.jsx should build the selected Pages Router route and include the Pages Router support entries required to render/export it, such as _app, _document, _error, 404, and 500.

Provide environment information

Reproduced with:

Next.js 16.2.4
Next.js 16.3.0-canary.10
React 18.3.1
macOS
Turbopack build

The repro uses:

  • a monorepo-shaped app in apps/web
  • a Pages Router dynamic route selected with --debug-build-paths
  • a custom pages/_document.jsx
  • a custom pages/_app.jsx
  • an App Router route in app/
  • i18n config
  • experimental.externalDir: true
  • outputFileTracingRoot pointing at the repo root
  • a Pages route importing code from packages/rank-ui outside the app directory

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

Turbopack, Pages Router, CLI (next build)

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

next build

Additional context

A similar single-folder app with the same Pages route, _document, App Router route, and i18n config does not reproduce this. The failure appears when the app is monorepo-shaped and the selected Pages Router route imports from outside the app directory with experimental.externalDir enabled.

In a larger app we traced this to selective build path handling: route discovery can identify the selected Pages Router route, but the Turbopack build output can omit required Pages Router entries from server/pages-manifest.json, causing PageNotFoundError for /_document during page data collection.

extent analysis

TL;DR

The most likely fix involves adjusting the selective build path handling to ensure required Pages Router entries are included in the server/pages-manifest.json file.

Guidance

  • Verify that the --debug-build-paths option is correctly configured to include the necessary Pages Router routes, such as _document, _app, _error, 404, and 500.
  • Check the server/pages-manifest.json file to confirm that it contains all the required Pages Router entries after running the next build command.
  • Consider disabling experimental.externalDir or adjusting the outputFileTracingRoot configuration to see if it resolves the issue.
  • Review the monorepo setup and the import of code from packages/rank-ui to ensure it is not causing the selective build path handling to omit required Pages Router entries.

Example

No specific code snippet is provided as the issue seems to be related to the configuration and setup of the Next.js project rather than a specific code error.

Notes

The issue appears to be specific to the monorepo setup with experimental.externalDir enabled and the import of code from outside the app directory. The fix may involve adjusting the configuration or the project setup to ensure that the selective build path handling includes all required Pages Router entries.

Recommendation

Apply a workaround by adjusting the --debug-build-paths option or the project configuration to ensure that all required Pages Router entries are included in the server/pages-manifest.json file. This is because the issue seems to be related to the selective build path handling and the monorepo setup, and upgrading to a fixed version is not explicitly mentioned as an option.

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 - 💡(How to fix) Fix Turbopack debug-build-paths omits Pages Router _document in monorepo externalDir app [1 participants]