-
Notifications
You must be signed in to change notification settings - Fork 26k
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
Error occurred prerendering page - 14.0.2+ #58576
Comments
Same here, but I'm using also lottie-react at this component: FourOhFour Component 'use client';
import Link from 'next/link';
import { FourOhFourContainer } from '../../../../styles/globalStyles';
import { useLottie } from 'lottie-react';
import { Button } from '@nextui-org/react';
export default function FourOhFour() {
const options = {
loop: true,
autoplay: true,
path: 'https://assets7.lottiefiles.com/packages/lf20_u1xuufn3.json',
};
const { View } = useLottie(options);
return (
<FourOhFourContainer>
<h1 style={{ marginTop: '2em' }}>Page Not Found</h1>
<div className="lottie">{View}</div>
<Link href="/">
<Button size="xl" color="secondary" variant="ghost">
Zurück
</Button>
</Link>
</FourOhFourContainer>
);
} Error at build inside Docker 🐳 Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
│ ┃ ReferenceError: document is not defined
│ ┃ at createTag (/app/.next/server/chunks/448.js:1:8065)
│ ┃ at /app/.next/server/chunks/448.js:1:23192
│ ┃ at /app/.next/server/chunks/448.js:1:23322
│ ┃ at /app/.next/server/chunks/448.js:1:26694
│ ┃ at /app/.next/server/chunks/448.js:1:7724
│ ┃ at 24521 (/app/.next/server/chunks/448.js:1:7729)
│ ┃ at __webpack_require__ (/app/.next/server/webpack-runtime.js:1:146)
│ ┃ at 35133 (/app/.next/server/chunks/448.js:1:552)
│ ┃ at __webpack_require__ (/app/.next/server/webpack-runtime.js:1:146)
│ ┃ at 10162 (/app/.next/server/chunks/558.js:1:565) |
This appears to be related somewhat to using
We have a monorepo setup, whereby we are sharing components between the 2 apps. The main app is running on Express and uses Removing the |
No use of this |
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 |
I also faced this issue when building docker image, resolved by following this guide: https://github.com/vercel/next.js/tree/canary/examples/with-docker |
Hi, what are the specifics around how you resolved the issue? I can't see much in that example repo other than the basic Next.js setup. |
It's the |
Ah ok thanks. We have that set in our config, so unfortunately doesn't fix the issue for us. |
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 EDIT: I managed to fix this by deleting node_modules and lockfile, and running the install command and then the build command! |
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. |
We're still experiencing this issue on the latest canary release, so no changes yet I'm afraid. |
I am also having same issue: |
Still occurring for us on the latest canary release. Tested #58576 (comment) 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. |
I have been encountering the same error. The only way I got it to go away was to upgrade Yarn to v4 |
Error occurred prerendering page "/management/roles". Read more: https://nextjs.org/docs/messages/prerender-error
I have this error in the version next.js 14.1.0 |
having the same error in version next.js 14.1.0 .. as much as I don't want to upgrade to this version coming from 13.4.19. I need it since it has the workaround shallow routing marked answer here: #48110 edit: I settled for 14.0.5-canary.17 as the build goes through and I can use the windowHistorySupport experimental flag. |
For a workaround you can import as dynamic with ssr: false prop: // import FourOhFour from '@/app/[locale]/_components/notFound/notFound.component';
import dynamic from 'next/dynamic';
const DynamicNotFound = dynamic(
() => import('./[locale]/_components/notFound/notFound.component'),
{ ssr: false }
);
export default function NotFound() {
return <DynamicNotFound />;
} |
this one works for me |
👍 Thanks, fixed as well my issue in a Prismic context (https://github.com/prismicio/slice-machine) and its generated slices/index.ts file with dynamic use but without { ssr: false} |
i meet the same error, but when I am using NODE_ENV=production and rebuild, the error is disappear |
We're also getting this issue on Next.js The error(s) we get are variations of this:
|
I've run into this problem too, and it came out of the blue, 1 hour ago my build was fine, then the next build reported an error, I found some options, but couldn't solve it completely. |
I solve this problem in my project, add a page to act as a buffer in the components that use import GiftCard from './purchase-gift-card'
export const dynamic = "force-dynamic";
export const fetchCache = "force-no-store";
export default function Page(){
return (<GiftCard />)
} |
After weeks of having this issue, I finally found a solution! 😊 The issue is caused by the fact that I was running The reason why it worked for many of you in Vercel and not locally is simply that Vercel properly sets Because I was using |
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 🚀 |
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 |
same error on 14.1.3 for us: during the build ReferenceError: Cannot access 'u' before initialization |
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 have tried everything for 2 days. nor a workaround for this. 😿 |
Same here, it builds locally, but when i deploy to azure devops i get:
i'm using |
Could anyone still having troubles with this error provide a minimal reproduction with |
I had encoutered this with every next version starting from 14.0.0.
This is resolved by locating the circular reference in my import/exports. |
We ended up finding a workaround as this was breaking ~50% of our builds and wasting so many build minutes.
Example import { NextPageContext } from 'next';
import dynamic from 'next/dynamic';
// The dynamic import probably isn't required but I'm sick of dealing with this issue.
const NextError = dynamic(() => import('next/error'), { ssr: false });
function Error({ statusCode }) {
return <NextError statusCode={statusCode} />;
}
Error.getInitialProps = ({ res, err }: NextPageContext) => {
const statusCode = res ? res.statusCode : err ? err.statusCode : 404;
return { statusCode };
};
export default Error; |
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
|
Still having this error on Next.js 14.1.3. Workaround with dynamic imports did not help. |
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 |
@NathanFrank285 there should be logs though? Please share the entire build logs. |
I solved this by adding "use client" wherever I use nextui. Or extract the logic to a client component and import it in the server component . |
In my case, I can build it locally, but can not build it in Docker. |
I managed to come across this issue in nextjs 14.2.2. I created a global-error page and then all my pages started to fail when running the build on my pipelines, locally it worked just fine. Removing the global-error.ts fixed it for me. |
Just as a follow up, I reintroduced the global-error page to the app but this time; I removed all components which required any logic. It is a plan html page and with this change the build works for me |
Adding
|
For anyone who is running into this issue using next in conjunction with thanks @kikohz |
Link to the code that reproduces this issue
https://github.com/bbc/simorgh/tree/latest/ws-nextjs-app
To Reproduce
ws-nextjs-app
directoryyarn
to install dependenciesyarn build
next
version to14.0.2
or onwardsyarn
yarn build
Error occurred prerendering page
error should occur atGenerating static pages
stepCurrent vs. Expected behavior
Updating to
14.0.2
onwards has caused theGenerating static pages
step to throw aError occurred prerendering page
error when runningnext build
:This error does not occur on
14.0.1
and prior.Verify canary release
Provide environment information
Which area(s) are affected? (Select all that apply)
Not sure
Additional context
No response
NEXT-2416
The text was updated successfully, but these errors were encountered: