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

create-next-app fails when running global next build, but not npm run build #76103

Closed
kylejrp opened this issue Feb 17, 2025 · 3 comments
Closed
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application.

Comments

@kylejrp
Copy link

kylejrp commented Feb 17, 2025

Link to the code that reproduces this issue

https://github.com/kylejrp/create-next-app-repro

To Reproduce

I have a video of me following the reproduction steps here:
https://youtu.be/WTWXyvQVq_A

This issue occurs when running the globally installed next build on a fresh install. It does not reproduce when running npm run build. This reproduces on my main development machine, but for clarity I reproduced it here on a fresh virtual machine.

  1. Create a fresh Windows Virtual Machine (for example, Windows Sandbox)
  2. Install the latest Node LTS from https://nodejs.org/en/download
  3. Open a PowerShell window
  4. Run Set-ExecutionPolicy RemoteSigned to allow npx.ps1 to be run in the next step
  5. Run npx create-next-app my-app and accept all the default options
  6. Run cd my-app
  7. Run npm install -g next
  8. Run next build

Current vs. Expected behavior

Expected: The build should successfully complete.
Actual: The build fails with the following error:

   ▲ Next.js 15.1.7

   Creating an optimized production build ...
 ✓ Compiled successfully
 ✓ Linting and checking validity of types
 ✓ Collecting page data
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useContext')
    at t.useContext (C:\Users\WDAGUtilityAccount\Desktop\my-app\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:68:6274)
    at w (C:\Users\WDAGUtilityAccount\Desktop\my-app\.next\server\chunks\106.js:1:16041)
    at nO (C:\Users\WDAGUtilityAccount\AppData\Roaming\npm\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:20:45959)
    at nI (C:\Users\WDAGUtilityAccount\AppData\Roaming\npm\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:20:47734)
    at nI (C:\Users\WDAGUtilityAccount\AppData\Roaming\npm\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:20:62515)
    at nL (C:\Users\WDAGUtilityAccount\AppData\Roaming\npm\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:20:65533)
    at nN (C:\Users\WDAGUtilityAccount\AppData\Roaming\npm\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:20:63164)
    at nB (C:\Users\WDAGUtilityAccount\AppData\Roaming\npm\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:20:68946)
    at nI (C:\Users\WDAGUtilityAccount\AppData\Roaming\npm\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:20:59382)
    at nL (C:\Users\WDAGUtilityAccount\AppData\Roaming\npm\node_modules\next\dist\compiled\next-server\app-page.runtime.prod.js:20:65533)
Export encountered an error on /page: /, exiting the build.
 ⨯ Next.js build worker exited with code: 1 and signal: null

Provide environment information

'yarn' is not recognized as an internal or external command,
operable program or batch file.
'pnpm' is not recognized as an internal or external command,
operable program or batch file.

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Enterprise
  Available memory (MB): 4095
  Available CPU cores: 24
Binaries:
  Node: 22.14.0
  npm: 10.9.2
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 15.1.7 // Latest available version is detected (15.1.7).
  eslint-config-next: N/A
  react: 19.0.0
  react-dom: 19.0.0
  typescript: N/A
Next.js Config:
  output: N/A

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

create-next-app

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

next build (local)

Additional context

Some related issues, most closed due to not being reproducible:

@github-actions github-actions bot added the create-next-app Related to our CLI tool for quickly starting a new Next.js application. label Feb 17, 2025
@samcx
Copy link
Member

samcx commented Feb 18, 2025

@kylejrp Thank you for submitting an issue!

Is there a reason why you need to install next globally instead of running npm run build?

@kylejrp
Copy link
Author

kylejrp commented Feb 18, 2025

@samcx I don't personally have a reason for doing it - I'm just here trying to help someone's Stack Overflow question get answered 😄 https://stackoverflow.com/q/79444207/3023052

Based on the related issues, it seems like a number of people are installing it globally and running into this issue though. I wonder if there's some tutorial out there that recommends it - perhaps incorrectly? I know in the Stack Overflow question, they mentioned that Netlify was also attempting to run next build globally and it was failing in the same way. Not sure if that's something funky with Netlify's auto-detection of build commands though.

Is installing and running next globally officially supported?

@samcx
Copy link
Member

samcx commented Feb 19, 2025

I'm not 100% sure how it should be ran on hosting platforms, but locally, by using npm run build, you ensure that the build process uses the exact version of Next.js and other dependencies specified in your project's package.json file . This helps maintain consistency across different environments and prevents potential issues caused by mismatched versions, etc.

Our documentation is also only shown this way as well.

I'll be closing this issue in the meantime unless there is a case to be using next globally!

@samcx samcx closed this as completed Feb 19, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
create-next-app Related to our CLI tool for quickly starting a new Next.js application.
Projects
None yet
Development

No branches or pull requests

2 participants