next.js: Unable to build project, Cannot read properties of null (reading 'useContext')
Link to the code that reproduces this issue
https://github.com/zlace/next-build-error
To Reproduce
pnpm dev works, pnpm build fails
https://stackblitz.com/edit/github-cmffvl?file=README.md
Current vs. Expected behavior
Should build successfully
Provide environment information
Operating System:
Platform: darwin
Arch: arm64
Version: Darwin Kernel Version 23.1.0: Thu Sep 14 23:08:13 PDT 2023; root:xnu-10002.40.63.505.1~3/RELEASE_ARM64_T8112
Binaries:
Node: 18.19.1
npm: 10.2.4
Yarn: 1.22.21
pnpm: 8.12.1
Relevant Packages:
next: 14.1.3
eslint-config-next: 14.1.1
react: 18.2.0
react-dom: 18.2.0
typescript: 5.4.2
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Module resolution (CJS / ESM, module resolving)
Which stage(s) are affected? (Select all that apply)
next build (local), Vercel (Deployed)
Additional context
No response
About this issue
- Original URL
- State: closed
- Created 3 years ago
- Reactions: 11
- Comments: 31 (4 by maintainers)
I get this error in dev all the time on dev server with Next 14.2.0 with
--turbo, never on build on production. refreshing often fixes it but once it stops working I need to restart the dev server.Here is the call stack:
I’m facing the same issue
I can reproduce it. Changing the authOptions for next-auth while application is running in dev mode triggers the same error everytime. I always restart the server to fix the problem, It’s extreamly annoying.
Hopefully that will help put someone on the right track to solve it. However, I am not using next-auth, so it’s not limited to just that. But it clearly has something to do with changing some code while in dev mode.
Same kind of issue here, although mine is happening in dev. seems to be coming from serverside. NextJS 14.2.3 with --turbo
If I remove turbo the app is so slow that it is better to get random crashes lol
Facing this and been scratching my head for hours.
What seems to work is to run the build with experimental compile mode.
Related comments/issues regarding this flag: https://github.com/vercel/next.js/discussions/46544#discussioncomment-7115457
Extra info:
I can confirm this run well on my local and production in Vercel. I’m using dynamic rendering anyway since its more of a “CMS” rather than static blog, so this seems fitting in my case.
The same issue happens with my projects that don’t use turbo.
Occurs with a custom development server, >
"dev": .env.development.local npm run dev-serverand also occurs with npx next dev. >npx next devI’m currently using both routers because I’m switching the service from pageRouter to AppRouter.
My error is
next/routerornext/navigationto access other routers. - Omy version
This issue is only comes with --turbo flag. When i don’t use turbo-pack i don’t face the issue. Seems like the turbo pack has issues with other packages.
My versions: next@14.1.4 react@18.2.0 react@18.2.0