Skip to content

Commit

Permalink
improve error message for conflicting parallel segments (#53803)
Browse files Browse the repository at this point in the history
This is a follow-up to log both conflicting paths & a link to route group docs, which I believe is the only scenario someone could trigger this

- #53752
  • Loading branch information
ztanner authored Aug 9, 2023
1 parent 7d67f00 commit 712669f
Show file tree
Hide file tree
Showing 2 changed files with 6 additions and 3 deletions.
7 changes: 5 additions & 2 deletions packages/next/src/build/webpack/loaders/next-app-loader.ts
Original file line number Diff line number Diff line change
Expand Up @@ -437,12 +437,14 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {
pathname: string
): [string, string | string[]][] => {
const matched: Record<string, string | string[]> = {}
let existingChildrenPath: string | undefined
for (const appPath of normalizedAppPaths) {
if (appPath.startsWith(pathname + '/')) {
const rest = appPath.slice(pathname.length + 1).split('/')

// It is the actual page, mark it specially.
if (rest.length === 1 && rest[0] === 'page') {
existingChildrenPath = appPath
matched.children = PAGE_SEGMENT
continue
}
Expand All @@ -464,12 +466,13 @@ const nextAppLoader: AppLoader = async function nextAppLoader() {

// avoid clobbering existing page segments
// if it's a valid parallel segment, the `children` property will be set appropriately
if (matched.children && matched.children !== rest[0]) {
if (existingChildrenPath && matched.children !== rest[0]) {
throw new Error(
`/You cannot have two parallel pages that resolve to the same path. Please check ${appPath}.`
`You cannot have two parallel pages that resolve to the same path. Please check ${existingChildrenPath} and ${appPath}. Refer to the route group docs for more information: https://nextjs.org/docs/app/building-your-application/routing/route-groups`
)
}

existingChildrenPath = appPath
matched.children = rest[0]
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -211,7 +211,7 @@ createNextDescribe(

await check(
() => next.cliOutput,
/You cannot have two parallel pages that resolve to the same path./i
/You cannot have two parallel pages that resolve to the same path\. Please check \/parallel\/\(new\)\/@baz\/nested-2\/page and \/parallel\/nested-2\/page\./i
)
}
await next.stop()
Expand Down

0 comments on commit 712669f

Please # to comment.