Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Can't build project - TypeError: Cannot read properties of null (reading 'useContext') #65413

Closed
Zweird-958 opened this issue May 6, 2024 · 6 comments
Labels
bug Issue was opened via the bug report template.

Comments

@Zweird-958
Copy link

Link to the code that reproduces this issue

https://github.com/Zweird-958/my-wishlist

To Reproduce

  1. Clone this repo
  2. Do a cd apps/web
  3. Do a bun run build

Current vs. Expected behavior

Should build successfully

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 23.4.0: Fri Mar 15 00:10:42 PDT 2024; root:xnu-10063.101.17~1/RELEASE_ARM64_T6000
  Available memory (MB): 32768
  Available CPU cores: 10
Binaries:
  Node: 20.9.0
  npm: 10.1.0
  Yarn: 1.22.21
  pnpm: 9.0.6
Relevant Packages:
  next: 14.2.3 // Latest available version is detected (14.2.3).
  eslint-config-next: 14.2.3
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.4.5
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Not sure

Which stage(s) are affected? (Select all that apply)

next build (local), Vercel (Deployed)

Additional context

I have no error with a next dev but next build don't work.
I'm using bun and also it's a monorepo.
I tried to delete all my pages and get only one page.tsx but I have the same error.

Error:

 Generating static pages (0/5)  [    ]TypeError: Cannot read properties of null (reading 'useContext')
    at exports.useContext (/Users/julien/code/my-wishlist/apps/web/node_modules/react/cjs/react.production.min.js:24:495)
    at h (/Users/julien/code/my-wishlist/apps/web/.next/server/pages/_error.js:1:5995)
    at Wc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at $c (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at Zc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:145)

Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error

TypeError: Cannot read properties of null (reading 'useContext')
    at exports.useContext (/Users/julien/code/my-wishlist/apps/web/node_modules/react/cjs/react.production.min.js:24:495)
    at h (/Users/julien/code/my-wishlist/apps/web/.next/server/pages/_error.js:1:5995)
    at Wc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at $c (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at Zc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:145)
TypeError: Cannot read properties of null (reading 'useContext')
    at exports.useContext (/Users/julien/code/my-wishlist/apps/web/node_modules/react/cjs/react.production.min.js:24:495)
    at h (/Users/julien/code/my-wishlist/apps/web/.next/server/pages/_error.js:1:5995)
    at Wc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at $c (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at Zc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:145)

Error occurred prerendering page "/500". Read more: https://nextjs.org/docs/messages/prerender-error

TypeError: Cannot read properties of null (reading 'useContext')
    at exports.useContext (/Users/julien/code/my-wishlist/apps/web/node_modules/react/cjs/react.production.min.js:24:495)
    at h (/Users/julien/code/my-wishlist/apps/web/.next/server/pages/_error.js:1:5995)
    at Wc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:68:44)
    at Zc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:70:253)
    at Z (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:89)
    at $c (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at bd (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:77:404)
    at Z (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:76:217)
    at $c (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:78:98)
    at Zc (/Users/julien/code/my-wishlist/node_modules/react-dom/cjs/react-dom-server.browser.production.min.js:71:145)
 ✓ Generating static pages (5/5)

> Export encountered errors on following paths:
        /_error: /404
        /_error: /500
error: script "build" exited with code 1
@Zweird-958 Zweird-958 added the bug Issue was opened via the bug report template. label May 6, 2024
@Zweird-958 Zweird-958 changed the title Can't build project - Can't build project - TypeError: Cannot read properties of null (reading 'useContext') May 6, 2024
@icyJoseph
Copy link
Contributor

Have you tried removing the toaster from the layout?

@Zweird-958
Copy link
Author

Have you tried removing the toaster from the layout?

Yes, I also try to remove all pages, and create one with only <p>test</p> and remove all Providers and Toaster in my layout.tsx

@JoseSanchez54
Copy link

I have the same error, in next 14.1.0 all works but when I upgrade next version to 14.2.3 start the error (Only in vercel and npm run build)

@Zweird-958
Copy link
Author

I have the same error, in next 14.1.0 all works but when I upgrade next version to 14.2.3 start the error (Only in vercel and npm run build)

I tried to downgrade to 14.1.0 but I have always the same error.

@przpl
Copy link

przpl commented May 10, 2024

I had a similar error. I fixed it by recreating package-lock.json file. Remove node_modules directory and package-lock.json file and install packages npm i.

@Zweird-958
Copy link
Author

I had a similar error. I fixed it by recreating package-lock.json file. Remove node_modules directory and package-lock.json file and install packages npm i.

I don't know why now it worked whereas I already tried this.
Thank you so much @przpl 🙏

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

No branches or pull requests

4 participants