diff --git a/packages/next/src/build/webpack/loaders/next-app-loader.ts b/packages/next/src/build/webpack/loaders/next-app-loader.ts index b6298b213170c..559756f0d4a72 100644 --- a/packages/next/src/build/webpack/loaders/next-app-loader.ts +++ b/packages/next/src/build/webpack/loaders/next-app-loader.ts @@ -437,12 +437,14 @@ const nextAppLoader: AppLoader = async function nextAppLoader() { pathname: string ): [string, string | string[]][] => { const matched: Record = {} + 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 } @@ -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] } } diff --git a/test/e2e/app-dir/parallel-routes-and-interception/parallel-routes-and-interception.test.ts b/test/e2e/app-dir/parallel-routes-and-interception/parallel-routes-and-interception.test.ts index 865d6fdabe608..b18a87b36845d 100644 --- a/test/e2e/app-dir/parallel-routes-and-interception/parallel-routes-and-interception.test.ts +++ b/test/e2e/app-dir/parallel-routes-and-interception/parallel-routes-and-interception.test.ts @@ -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()