When the Pages Router and the App Router both generate a page for the same dynamic URL, running next build returns the following error:
> Build error occurred
Error: Invariant: page wasn't built
at C:\overlapping-app-router-pages-router\node_modules\next\dist\build\index.js:1727:47
at Array.map (<anonymous>)
at C:\overlapping-app-router-pages-router\node_modules\next\dist\build\index.js:1724:84
at async Span.traceAsyncFn (C:\overlapping-app-router-pages-router\node_modules\next\dist\trace\trace.js:151:20)
at async C:\overlapping-app-router-pages-router\node_modules\next\dist\build\index.js:1343:17
at async Span.traceAsyncFn (C:\overlapping-app-router-pages-router\node_modules\next\dist\trace\trace.js:151:20)
at async build (C:\overlapping-app-router-pages-router\node_modules\next\dist\build\index.js:374:9)
at async main (C:\overlapping-app-router-pages-router\node_modules\next\dist\bin\next:155:5)
The expected behavior is that the site builds without errors, and renders (app router) on the /one/two route and (pages router) on /one/three and /three/four.
If it's intentional that overlapping a pages route with an app route shouldn't work, I'd expect the error message to specifically reference that, printing out the conflicting routes and suggesting that the developer pick either app or pages, but not both.
Provide environment information
Operating System:
Platform: win32
Arch: x64
Version: Windows 10 Pro
Binaries:
Node: 18.19.0
npm: 10.2.5
Yarn: N/A
pnpm: N/A
Relevant Packages:
next: 14.1.1-canary.9 // Latest available version is detected (14.1.1-canary.9).
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: 5.3.3
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
App Router
Which stage(s) are affected? (Select all that apply)
Link to the code that reproduces this issue
https://github.com/dstaley/overlapping-app-router-pages-router
To Reproduce
next build
Current vs. Expected behavior
When the Pages Router and the App Router both generate a page for the same dynamic URL, running
next build
returns the following error:The expected behavior is that the site builds without errors, and renders
(app router)
on the/one/two
route and(pages router)
on/one/three
and/three/four
.If it's intentional that overlapping a pages route with an app route shouldn't work, I'd expect the error message to specifically reference that, printing out the conflicting routes and suggesting that the developer pick either app or pages, but not both.
Provide environment information
Which area(s) are affected? (Select all that apply)
App Router
Which stage(s) are affected? (Select all that apply)
next build (local), Vercel (Deployed)
Additional context
No response