Unverified Commit 54d12035 authored by Jiwon Choi's avatar Jiwon Choi Committed by GitHub

Fix route.replace crash with --debug-build-paths (#90312)

## Summary

- Fixes `route.replace is not a function` error when running `next build
--debug-build-paths` on projects with parallel routes

**Root cause:** Turbopack filters routes at the route level (e.g.,
`/parallel-test` includes all page entries), while JS route discovery
filters at the file path level (e.g., only
`app/parallel-test/page.tsx`). This causes the `appPathsManifest` to
contain entries (like `/@sidebar/page`) that `mappedAppPages` doesn't
have. The unguarded lookup at
`mappedAppPages[originalPath].replace(...)` crashes on `undefined`.

**Fix:** Added a guard to skip manifest entries that don't exist in
`mappedAppPages`.

## Test plan

- [x] Verified `next build --debug-build-paths
'app/parallel-test/**/page.tsx'` succeeds on test fixture
- [x] Verified other `--debug-build-paths` patterns still work
(multi-page, pages-only, etc.)
parent 1fedf5b0
......@@ -2185,7 +2185,10 @@ export default async function build(
for (const [originalPath, normalizedPath] of Object.entries(
appPathRoutes
)) {
if (normalizedPath === page) {
if (
normalizedPath === page &&
mappedAppPages[originalPath]
) {
pagePath = mappedAppPages[originalPath].replace(
/^private-next-app-dir/,
''
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment