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

next build failing after fresh npx create-next-app@latest #50434

Closed
1 task done
thimmey opened this issue May 27, 2023 · 15 comments
Closed
1 task done

next build failing after fresh npx create-next-app@latest #50434

thimmey opened this issue May 27, 2023 · 15 comments
Labels
bug Issue was opened via the bug report template. locked please add a complete reproduction Please add a complete reproduction.

Comments

@thimmey
Copy link

thimmey commented May 27, 2023

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: win32
      Arch: x64
      Version: Windows 10 Pro
    Binaries:
      Node: 18.16.0
      npm: N/A
      Yarn: N/A
      pnpm: N/A
    Relevant packages:
      next: 13.4.5-canary.0
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

build

Link to the code that reproduces this issue or a replay of the bug

no changes done to the code, coming like this without any modification

To Reproduce

install nextjs and install the standard app through "npx create-next-app@latest"
√ Would you like to use TypeScript with this project? ... No
√ Would you like to use ESLint with this project? ... No
√ Would you like to use Tailwind CSS with this project? ... No
√ Would you like to use src/ directory with this project? ... No
√ Use App Router (recommended)? ... Yes
√ Would you like to customize the default import alias? ... No

I tried also the nextjs canary version, + 6 lower versions (went down to version 13.1.0, there it fails with some google font issues...) for the next installation itself and the next create-next-app.

Describe the Bug

"next build" as it throws error

I'm trying to get the standard version running. Using VS Code on Windows. I created a new app by running "npx create-next-app@latest" After this I am running "next build" and this is failing. I did not modify anything.
For a new joiner like me this is a big frustration.

PS C:\temp\nextjs-testing\my-test-app> next build

  • info Linting and checking validity of types
  • info Creating an optimized production build
  • info Compiled successfully
  • info Collecting page data
    [ ] - info Generating static pages (0/3)TypeError: Cannot read properties of null (reading 'useContext')
    at exports.useContext (C:\temp\nextjs-testing\my-test-app\node_modules\react\cjs\react.production.min.js:24:118)
    at Head (C:\temp\nextjs-testing\my-test-app.next\server\pages_error.js:282:44)
    at Wc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:44)
    at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:253)
    at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89)
    at $c (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98)
    at bd (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:77:404)
    at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:217)
    at $c (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98)
    at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\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 (C:\temp\nextjs-testing\my-test-app\node_modules\react\cjs\react.production.min.js:24:118)
at Head (C:\temp\nextjs-testing\my-test-app.next\server\pages_error.js:282:44)
at Wc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:44)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:253)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89)
at $c (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98)
at bd (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:77:404)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:217)
at $c (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\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 (C:\temp\nextjs-testing\my-test-app\node_modules\react\cjs\react.production.min.js:24:118)
at Head (C:\temp\nextjs-testing\my-test-app.next\server\pages_error.js:282:44)
at Wc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:44)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:253)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89)
at $c (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98)
at bd (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:77:404)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:217)
at $c (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\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 (C:\temp\nextjs-testing\my-test-app\node_modules\react\cjs\react.production.min.js:24:118)
at Head (C:\temp\nextjs-testing\my-test-app.next\server\pages_error.js:282:44)
at Wc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:44)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:253)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89)
at $c (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98)
at bd (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:77:404)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:217)
at $c (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:78:98)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\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 (C:\temp\nextjs-testing\my-test-app\node_modules\react\cjs\react.production.min.js:24:118)
at Html (C:\temp\nextjs-testing\my-test-app.next\server\pages_document.js:719:114)
at Wc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:44)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:253)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89)
at Xc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:409)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:210)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:74:209)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89)

Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useContext')
at exports.useContext (C:\temp\nextjs-testing\my-test-app\node_modules\react\cjs\react.production.min.js:24:118)
at Html (C:\temp\nextjs-testing\my-test-app.next\server\pages_document.js:719:114)
at Wc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:44)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:253)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89)
at Xc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:68:409)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:70:210)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89)
at Zc (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:74:209)
at Z (C:\Users\Tim\AppData\Roaming\npm\node_modules\next\node_modules\react-dom\cjs\react-dom-server.browser.production.min.js:76:89)

  • info Generating static pages (3/3)

Export encountered errors on following paths:
/
/_error: /404
/_error: /500
PS C:\temp\nextjs-testing\my-test-app>

Expected Behavior

no error when trying to build fresh install / created app through "npx create-next-app@latest"

Which browser are you using? (if relevant)

Not relevant

How are you deploying your application? (if relevant)

No

@thimmey thimmey added the bug Issue was opened via the bug report template. label May 27, 2023
@peter-iglaev
Copy link

same issue

{
  "name": "my-next-app",
  "version": "0.1.0",
  "private": true,
  "scripts": {
    "dev": "next dev",
    "build": "next build",
    "start": "next start",
    "lint": "next lint"
  },
  "dependencies": {
    "@emotion/react": "^11.11.0",
    "@emotion/styled": "^11.11.0",
    "@mui/material": "^5.13.0",
    "@stripe/react-stripe-js": "^2.1.0",
    "@stripe/stripe-js": "^1.53.0",
    "autoprefixer": "10.4.14",
    "circular-json": "^0.5.9",
    "eslint": "8.40.0",
    "eslint-config-next": "13.4.2",
    "next": "13.4.5-canary.0",
    "postcss": "8.4.23",
    "react": "18.2.0",
    "react-dom": "18.2.0",
    "react-firebase-hooks": "^5.1.1",
    "react-icons": "^4.7.1",
    "tailwindcss": "3.3.2"
  }
}

@balazsorban44 balazsorban44 added the please add a complete reproduction Please add a complete reproduction. label May 29, 2023
@github-actions
Copy link
Contributor

We cannot recreate the issue with the provided information. Please add a reproduction in order for us to be able to investigate.

Why was this issue marked with the please add a complete reproduction label?

To be able to investigate, we need access to a reproduction to identify what triggered the issue. We prefer a link to a public GitHub repository (template for pages, template for App Router), but you can also use these templates: CodeSandbox: pages or CodeSandbox: App Router.

To make sure the issue is resolved as quickly as possible, please make sure that the reproduction is as minimal as possible. This means that you should remove unnecessary code, files, and dependencies that do not contribute to the issue.

Please test your reproduction against the latest version of Next.js (next@canary) to make sure your issue has not already been fixed.

I added a link, why was it still marked?

Ensure the link is pointing to a codebase that is accessible (e.g. not a private repository). "example.com", "n/a", "will add later", etc. are not acceptable links -- we need to see a public codebase. See the above section for accepted links.

What happens if I don't provide a sufficient minimal reproduction?

Issues with the please add a complete reproduction label that receives no meaningful activity (e.g. new comments with a reproduction link) are automatically closed and locked after 30 days.

If your issue has not been resolved in that time and it has been closed/locked, please open a new issue with the required reproduction.

I did not open this issue, but it is relevant to me, what can I do to help?

Anyone experiencing the same issue is welcome to provide a minimal reproduction following the above steps. Furthermore, you can upvote the issue using the 👍 reaction on the topmost comment (please do not comment "I have the same issue" without reproduction steps). Then, we can sort issues by votes to prioritize.

I think my reproduction is good enough, why aren't you looking into it quicker?

We look into every Next.js issue and constantly monitor open issues for new comments.

However, sometimes we might miss one or two due to the popularity/high traffic of the repository. We apologize, and kindly ask you to refrain from tagging core maintainers, as that will usually not result in increased priority.

Upvoting issues to show your interest will help us prioritize and address them as quickly as possible. That said, every issue is important to us, and if an issue gets closed by accident, we encourage you to open a new one linking to the old issue and we will look into it.

Useful Resources

@rossanodr
Copy link

same here

@leerob
Copy link
Member

leerob commented Jun 26, 2023

As mentioned above, please add a reproduction 🙏

@hms-dev25
Copy link

I had a similar issue. Downgrading next to 13.3.4 fixed the issue for me.

@happydayxxl
Copy link

got the same error:
npx create-next-app@latest
cd to the app name
next build

"dependencies": {
"@azure/msal-browser": "^3.1.0",
"@headlessui/react": "^1.7.17",
"axios": "^1.5.0",
"next": "^13.5.4",
"react": "^18.2.0",
"react-calendar": "^4.6.0",
"react-dom": "^18.2.0",
"react-icons": "^4.11.0"
},
"devDependencies": {
"@types/node": "^20.8.2",
"@types/react": "^18.2.24",
"@types/react-dom": "^18.2.8",
"@typescript-eslint/eslint-plugin": "^6.7.4",
"@typescript-eslint/parser": "^6.7.4",
"autoprefixer": "^10.4.16",
"eslint": "^8.50.0",
"eslint-config-next": "^13.5.4",
"postcss": "^8.4.31",
"tailwindcss": "^3.3.3",
"typescript": "^5.2.2"
}

=> Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of null (reading 'useContext')
=> Error: should not be imported outside of pages/_document.
Read more: https://nextjs.org/docs/messages/no-document-import-in-page
=> Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
Error: should not be imported outside of pages/_document.
=> Error occurred prerendering page "/500". Read more: https://nextjs.org/docs/messages/prerender-error
Error: should not be imported outside of pages/_document.
=> Export encountered errors on following paths:
/(startPage)/page: /
/_error: /404
/_error: /500
/_not-found

@kletse
Copy link
Contributor

kletse commented Oct 4, 2023

install nextjs and install the standard app through "npx create-next-app@latest"
√ Would you like to use TypeScript with this project? ... No
√ Would you like to use ESLint with this project? ... No
√ Would you like to use Tailwind CSS with this project? ... No
√ Would you like to use src/ directory with this project? ... No
√ Use App Router (recommended)? ... Yes
√ Would you like to customize the default import alias? ... No

"next build" as it throws error

These are the parts to reproduce the issue.

The last line where you run "next build" directly, and not "npm run build" is crucial and reproduces the error

This would assume you have next installed globally (npm i -g next)

@happydayxxl
Copy link

√ What is your project named? ... test
√ Would you like to use TypeScript? ... No / Yes
√ Would you like to use ESLint? ... No / Yes
√ Would you like to use Tailwind CSS? ... No / Yes
√ Would you like to use src/ directory? ... No / Yes
√ Would you like to use App Router? (recommended) ... No / Yes
√ Would you like to customize the default import alias (@/*)? ... No / Yes

i ran -> npm run build

....

test@0.1.0 build
next build

⚠ You are using a non-standard "NODE_ENV" value in your environment. This creates inconsistencies in the project and is strongly advised against. Read more: https://nextjs.org/docs/messages/non-standard-node-env
✓ Creating an optimized production build
✓ Compiled successfully
✓ Linting and checking validity of types
✓ Collecting page data
Generating static pages (0/5) [== ]Error: should not be imported outside of pages/_document.
Read more: https://nextjs.org/docs/messages/no-document-import-in-page

@happydayxxl
Copy link

next is not globally installed on my system:
C:\Users\username\WebstormProjects>npm list -g
C:\Users\username\AppData\Roaming\npm
+-- cordova@12.0.0
+-- expo-cli@6.3.7
+-- gradle@1.2.4
+-- npm@9.6.5
`-- yarn@1.22.19

@kletse
Copy link
Contributor

kletse commented Oct 9, 2023

@happydayxxl I was just providing clearer instructions on how to reproduce the error described in the issue by @thimmey .

Your error seems like a different error, with other steps needed to reproduce it. Might be better to create a separate issue for that one.

@studentIvan
Copy link

studentIvan commented Oct 18, 2023

Same error randomly occurred the production build for us after upgrade the next to the latest stable version...

15:52:38: #13 71.91 Error occurred prerendering page "/en-US/contact". Read more: https://nextjs.org/docs/messages/prerender-error
15:52:38: #13 71.91 TypeError: Cannot read properties of null (reading 'useContext')
15:52:38: #13 71.91     at t.useContext (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:59:6849)
15:52:38: #13 71.91     at usePathname (/app/.next/server/chunks/1682.js:1:2**64)
15:52:38: #13 71.91     at ErrorBoundary (/app/.next/server/chunks/1682.js:1:12259)
15:52:38: #13 71.91     at oX (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:11:72647)
15:52:38: #13 71.91     at /app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:11:77426
15:52:38: #13 71.91     at ae (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:11:79**0)
15:52:38: #13 71.91     at e (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:11:111506)
15:52:38: #13 71.91     at ar (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:11:113484)
15:52:38: #13 71.91     at o5 (/app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:11:74065)
15:52:38: #13 71.91     at /app/node_modules/next/dist/compiled/next-server/app-page.runtime.dev.js:11:79156
15:52:38:  ✓ Generating static pages (168/168) 

Build environment: nixpacks docker aws

@balazsorban44
Copy link
Member

I could not see a reproduction in any of the follow-up comment, so closing. Feel free to reopen with a new reproduction if you are still seeing this!

@kletse
Copy link
Contributor

kletse commented Oct 23, 2023

#50434 (comment)

This really reproduces the error. Jus tried it again.

@hamlim
Copy link
Contributor

hamlim commented Oct 24, 2023

I was running into the same issue in a few of my side projects, tried rolling back a few versions (13.4.9 seemed to be the last stable release for me).

Figured out that it seemed to be happening when attempting to statically render the error pages (404/500), so I added a pages/_error.tsx page with a stubbed error component + an empty getServerSideProps:

export default function ErrorPage() {
  return <pre>Encountered an error!</pre>
}

export async function getServerSideProps() {
  return { props: {} }
}

and the builds finally pass (even on newer Next.js versions!)

Copy link
Contributor

github-actions bot commented Nov 7, 2023

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

@github-actions github-actions bot added the locked label Nov 7, 2023
@github-actions github-actions bot locked as resolved and limited conversation to collaborators Nov 7, 2023
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
bug Issue was opened via the bug report template. locked please add a complete reproduction Please add a complete reproduction.
Projects
None yet
Development

No branches or pull requests

10 participants