next.js: Error occurred prerendering page - 14.0.2+
Link to the code that reproduces this issue
https://github.com/bbc/simorgh/tree/latest/ws-nextjs-app
To Reproduce
- Navigate to
ws-nextjs-app
directory - Run
yarn
to install dependencies - Run
yarn build
- Confirm it works
- Update the
next
version to14.0.2
or onwards - Run
yarn
- Run
yarn build
Error occurred prerendering page
error should occur atGenerating static pages
step
Current vs. Expected behavior
Updating to 14.0.2
onwards has caused the Generating static pages
step to throw a Error occurred prerendering page
error when running next build
:
Generating static pages (0/2) [== ]
Error occurred prerendering page "/404". Read more: https://nextjs.org/docs/messages/prerender-error
ReferenceError: Cannot access 'v' before initialization
at Object.Z (/Users/moorea53/Documents/GitHub/simorgh/ws-nextjs-app/build/server/chunks/themes-afaanoromoo.js:1:19154)
at /Users/moorea53/Documents/GitHub/simorgh/ws-nextjs-app/build/server/chunks/themes-urdu.js:1:9598
at r.a (/Users/moorea53/Documents/GitHub/simorgh/ws-nextjs-app/build/server/webpack-runtime.js:1:864)
at 21101 (/Users/moorea53/Documents/GitHub/simorgh/ws-nextjs-app/build/server/chunks/themes-urdu.js:1:9241)
at Function.r (/Users/moorea53/Documents/GitHub/simorgh/ws-nextjs-app/build/server/webpack-runtime.js:1:127)
Error occurred prerendering page "/500". Read more: https://nextjs.org/docs/messages/prerender-error
ReferenceError: Cannot access 'v' before initialization
at Object.Z (/Users/moorea53/Documents/GitHub/simorgh/ws-nextjs-app/build/server/chunks/themes-afaanoromoo.js:1:19154)
at /Users/moorea53/Documents/GitHub/simorgh/ws-nextjs-app/build/server/chunks/themes-urdu.js:1:9598
at r.a (/Users/moorea53/Documents/GitHub/simorgh/ws-nextjs-app/build/server/webpack-runtime.js:1:864)
at 21101 (/Users/moorea53/Documents/GitHub/simorgh/ws-nextjs-app/build/server/chunks/themes-urdu.js:1:9241)
at Function.r (/Users/moorea53/Documents/GitHub/simorgh/ws-nextjs-app/build/server/webpack-runtime.js:1:127)
✓ Generating static pages (2/2)
> Export encountered errors on following paths:
/_error: /404
/_error: /500
This error does not occur on 14.0.1
and prior.
Verify canary release
- I verified that the issue exists in the latest Next.js canary release
Provide environment information
Operating System:
Platform: darwin
Arch: x64
Version: Darwin Kernel Version 22.6.0
Binaries:
Node: 18.17.1
npm: 9.6.7
Yarn: 3.6.4
pnpm: N/A
Relevant Packages:
next: 14.0.2
eslint-config-next: N/A
react: 18.2.0
react-dom: 18.2.0
typescript: N/A
Next.js Config:
output: standalone
Which area(s) are affected? (Select all that apply)
Not sure
Additional context
No response
About this issue
- Original URL
- State: open
- Created 7 months ago
- Reactions: 25
- Comments: 47 (5 by maintainers)
Commits related to this issue
- build: add workarounds for issue with npm run build command https://github.com/vercel/next.js/issues/58576 — committed to mateuszNadolny/chatter by mateuszNadolny 3 months ago
Same here, but I’m using also lottie-react at this component:
FourOhFour Component
Error at build inside Docker 🐳
We’re still experiencing this issue on the latest canary release, so no changes yet I’m afraid.
Im getting something very similar. Notice how its complaining about route /_not-found. However, in my project, and likely your project, does not have any route /_not-found. Per Next js docs, custom not_found pages are either in routes /[…not-found] or directly /not-found. No idea where this error is coming from
same error on 14.1.3 for us: during the build
ReferenceError: Cannot access ‘u’ before initialization
Trying to deploy to vercel. I’m using NX as monorepo and a next project. Basically when I am trying to merge and deploy my new branch I’m getting:
Still the same error on 14.1.3 for us.
We have got round the issue as we identified a code path that could result in one of our Contexts returning
null
when it shouldn’t, however this was not a problem prior to 14.0.2.For a workaround you can import as dynamic with ssr: false prop:
Was also getting this error on 14.2.1, had to downgrade to 14.1.4 and it is now working, not able to identify the source of the issue unfortunately other than it being on our “/” route
Could anyone still having troubles with this error provide a minimal reproduction with
next@canary
? The reproduction linked in the issue keeps updated. It looks like sth failed during static generation for the default built-in 404 page, but still depends on your case.Same here, it builds locally, but when i deploy to azure devops i get:
i’m using
"next": "^14.1.4"
It is working when I build locally but inside Docker I still get the same error and need to use the workaround with next/dynamic and set SSR to false 😭
I can confirm it is working now with v14.1.3. I set my NODE_ENV in my Dockerfile always to production so this was not my fix. So I don’t know why it is working now, but if you guys don’t face any errors we can close this issue 🚀
I am not facing this issue anymore in the latest NextJS version.
Try to console.log the response. I guess you dont hit the end endpoint or something similar and response.json() throws error. During build time nextjs prerenders the app and run it. At this time it using some url and this url is not the url you think probably.
I was using useSearchParams inside my Home component and I wrapped it using Suspense and it was fixed
i meet the same error, but when I am using NODE_ENV=production and rebuild, the error is disappear
this one works for me
I have been encountering the same error. The only way I got it to go away was to upgrade Yarn to v4
Still occurring for us on the latest canary release.
Tested https://github.com/vercel/next.js/issues/58576#issuecomment-1842780167 a bit more and whilst it works (as in no build errors and the app starts), it breaks SSR, so everything is client side rendered.
Any updates? I deleted the lock file and reinstalled the modules, but I’m still facing an issue. I’m using pnpm.
(edit) I’m experiencing the same issue on Next 14.0.1 and later versions. The problem doesn’t occur when building locally, but it surfaces when deploying to Vercel.
(edit) In my case, the cause of the error was that error handling was not in place when the data was not correctly loaded during dynamic page rendering.
I am facing the same issue when I try to run build command locally. Have spent a couple of hours going through making sure I follow the guidelines in the error message, nothing has worked so far. Also tried adding
output: "standalone"
tonext.config.js
as per suggestion above and this also didn’t work. Will continue looking into it, but the error message is not very clear or helpful.EDIT: I managed to fix this by deleting node_modules and lockfile, and running the install command and then the build command!
Ah ok thanks. We have that set in our config, so unfortunately doesn’t fix the issue for us.
We have the same issue. Occurs on next versions
14.0.2
,14.0.3
and14.0.4
No use of this
transform-rename-import
on my project, but still using babel too (due to no good SWC alternative of the formatJs plugins 😕)