Next.js Discord

Discord Forum

Build failing in monorepo: `Error: invariant expected app router to be mounted`

Unanswered
Northeast Congo Lion posted this in #help-forum
Open in Discord
Northeast Congo LionOP
Hi there - I have a nextjs app I'm moving over to use turborepo. We use the pages router, but use next/navigation over next/router for if/when we navigate over to the app router.

In our regular monolith, building works, no problem. Since I've moved everything over, I am getting the following littered throghout our build logs (and seemingly causing it to fail?):
│ Error occurred prerendering page "/callback/something". Read more: https://nextjs.org/docs/messages/prerender-error
│ Error: invariant expected app router to be mounted
│     at useRouter (/myproject/apps/web/.next/server/chunks/4916.js:1287:37)
│     at useSkewProtection (/myproject/apps/web/.next/server/chunks/2974.js:2102:78)
│     at MyApp (/myproject/apps/web/.next/server/chunks/2974.js:1388:101)
│     at renderWithHooks (/myproject/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5658:16)
│     at renderIndeterminateComponent (/myproject/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5
│ 732:15)
│     at renderElement (/myproject/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5957:7)
│     at renderNodeDestructiveImpl (/myproject/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6115
│ :11)
│     at renderNodeDestructive (/myproject/node_modules/react-dom/cjs/react-dom-server.browser.development.js:6087:14)
│     at renderIndeterminateComponent (/myproject/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5
│ 786:7)
│     at renderElement (/myproject/node_modules/react-dom/cjs/react-dom-server.browser.development.js:5957:7)
│ Export encountered an error on /404, exiting the build.


Has anyone seen this before, or know what might be happening? To be clear, we are not using app router in any way, and have never had issues with next/navigation in pages router historically.

1 Reply

Northeast Congo LionOP
For some additional context, we are using next 15.2.4, node 20.19. The only notable changes I can think of are the fact that we transpile the packages from our monorepo, and now our code lives in /src as opposed to being available at the top level... I don't think either of those should cause this but maybe there's something I'm missing