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

Error occurred prerendering page - 14.0.2+ #58576

Open
1 task done
amoore108 opened this issue Nov 17, 2023 · 51 comments
Open
1 task done

Error occurred prerendering page - 14.0.2+ #58576

amoore108 opened this issue Nov 17, 2023 · 51 comments
Labels
bug Issue was opened via the bug report template. linear: next Confirmed issue that is tracked by the Next.js team. please add a complete reproduction The issue lacks information for further investigation

Comments

@amoore108
Copy link

amoore108 commented Nov 17, 2023

Link to the code that reproduces this issue

https://github.com/bbc/simorgh/tree/latest/ws-nextjs-app

To Reproduce

  1. Navigate to ws-nextjs-app directory
  2. Run yarn to install dependencies
  3. Run yarn build
  4. Confirm it works
  5. Update the next version to 14.0.2 or onwards
  6. Run yarn
  7. Run yarn build
  8. Error occurred prerendering page error should occur at Generating 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

NEXT-2416

@amoore108 amoore108 added the bug Issue was opened via the bug report template. label Nov 17, 2023
@sFritsch09
Copy link

sFritsch09 commented Nov 19, 2023

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)

@orelhochenboym
Copy link

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:
image
image
image

@amoore108
Copy link
Author

amoore108 commented Dec 6, 2023

This appears to be related somewhat to using transform-rename-import in our Babel config:

    [
      "transform-rename-import",
      { "original": "@loadable/component", "replacement": "next/dynamic" }
    ]

We have a monorepo setup, whereby we are sharing components between the 2 apps. The main app is running on Express and uses @loadable for dynamic imports of modules. We added transform-rename-import to swap out the @loadable/component import with next/dynamic, which worked up until 14.0.2.

Removing the transform-rename-import from our Babel config lets the Next.js app build successfully on 14.0.2 onwards, however it results in the dynamic imports being rendered clientside, rather than rendering with SSR.

@webda2l
Copy link
Contributor

webda2l commented Dec 6, 2023

This appears to be related somewhat to using transform-rename-import in our Babel config:

    [
      "transform-rename-import",
      { "original": "@loadable/component", "replacement": "next/dynamic" }
    ]

We have a monorepo setup, whereby we are sharing components between the 2 apps. The main app is running on Express and uses @loadable for dynamic imports of modules. We added transform-rename-import to swap out the @loadable/component import with next/dynamic, which worked up until 14.0.2.

Removing the transform-rename-import from our Babel config lets the Next.js app build successfully on 14.0.2 onwards, however it results in the dynamic imports being rendered clientside, rather than rendering with SSR.

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 :/)

@garrettparris
Copy link

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

@JH1ller
Copy link

JH1ller commented Dec 12, 2023

We have the same issue. Occurs on next versions 14.0.2, 14.0.3 and 14.0.4

Screenshot 2023-12-12 at 14 49 48

@hunghuy201280
Copy link

hunghuy201280 commented Dec 13, 2023

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

@amoore108
Copy link
Author

I also faced this issue, 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.

@hunghuy201280
Copy link

I also faced this issue, 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 In existing projects section, I copied the Dockerfile and set output config to standalone

@amoore108
Copy link
Author

I also faced this issue, 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 In existing projects section, I copied the Dockerfile and set output config to standalone

Ah ok thanks. We have that set in our config, so unfortunately doesn't fix the issue for us.

@taylor-lindores-reeves
Copy link

taylor-lindores-reeves commented Dec 14, 2023

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" to next.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.

Screenshot 2023-12-14 at 13 34 17

EDIT: I managed to fix this by deleting node_modules and lockfile, and running the install command and then the build command!

@r-4bb1t
Copy link

r-4bb1t commented Dec 18, 2023

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.

@amoore108
Copy link
Author

We're still experiencing this issue on the latest canary release, so no changes yet I'm afraid.

@Sahillather002
Copy link

I am also having same issue:
Error occurred prerendering page "/marketing/sip-bonds". Read more: https://nextjs.org/docs/messages/prerender-error
FetchError: invalid json response body at 'here is my api call'
reason: Unexpected end of JSON input

@amoore108
Copy link
Author

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.

@napter
Copy link

napter commented Jan 14, 2024

I have been encountering the same error. The only way I got it to go away was to upgrade Yarn to v4

@camiloguz23
Copy link

Error occurred prerendering page "/management/roles". Read more: https://nextjs.org/docs/messages/prerender-error
✓ Generating static pages (14/14)

Export encountered errors on following paths:
/_not-found
/dashboard/page: /dashboard
/login/page: /login
/logout/page: /logout
/management/enterprise/page: /management/enterprise
/management/permissions/page: /management/permissions
/management/roles/page: /management/roles
/management/user/page: /management/user
/page: /
/settings/language/page: /settings/language
/settings/password/page: /settings/password
/settings/profile/page: /settings/profile

I have this error in the version next.js 14.1.0

@ellamurii
Copy link

ellamurii commented Feb 5, 2024

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.

@sFritsch09
Copy link

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 />;
}

@khantseithu
Copy link

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

@webda2l
Copy link
Contributor

webda2l commented Feb 9, 2024

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 />;
}

👍 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}

@liangmiQwQ
Copy link

i meet the same error, but when I am using NODE_ENV=production and rebuild, the error is disappear

@samcarton
Copy link

samcarton commented Mar 6, 2024

We're also getting this issue on Next.js v14.1.0 and v14.1.2, it is intermittent but persistent. Probably 50% of the time it happens. It happens in both local builds and on github actions. We build inside docker, and we do not use the standalone output option yet.

The error(s) we get are variations of this:

#20 464.7 Error occurred prerendering page "some/page". Read more: https://nextjs.org/docs/messages/prerender-error
#20 464.7 
#20 464.7 ReferenceError: Cannot access 'm' before initialization
#20 464.7     at Object.M (/app/.next/server/chunks/1690.js:201:7022)
#20 464.7     at /app/.next/server/chunks/9843.js:1:22947
#20 464.7     at t.a (/app/.next/server/webpack-runtime.js:1:906)
#20 464.7     at 543572 (/app/.next/server/chunks/9843.js:1:22305)
#20 464.7     at t (/app/.next/server/webpack-runtime.js:1:143)
#20 464.7     at /app/.next/server/chunks/9843.js:1:17667
#20 464.7     at t.a (/app/.next/server/webpack-runtime.js:1:906)
#20 464.7     at 887443 (/app/.next/server/chunks/9843.js:1:17513)
#20 464.7     at t (/app/.next/server/webpack-runtime.js:1:143)
#20 464.7     at /app/.next/server/chunks/9843.js:1:19[664]
  • Sometimes the 'm' is 'p'
  • We have routes on both pages and app router, but this error seems to only point to 1-3 routes on our pages router at a time.
  • The pages involved in the error are very simple - a mantine theme provider and a loading spinner. One of the other pages is a little more complicated.
  • We have tried the dynamic import with no SSR for the entire component rendered by these pages, and they still appear in the errors...
  • I have also seen the internal nextjs 500 page mentioned in this error, which makes no sense. We don't have custom error\500 pages set up on any routes.
  • We have tried migrating to Yarn4 (still using node-modules nodeLinker) and still encounter this issue
  • We have tried forcing SSR for the pages (just add a getServerSideProps that returns { props: {} }), and while it fixes the one or two pages mentioned in the errors, inevitably another set of 1-3 of our static generated pages appears in the error logs next time.
  • We have since forced SSR for all of our static pages, added custom 404 and 500 pages that just dynamically import the next/error component, and yet we still get Error occurred prerendering page for both the 404 and 500s.

@kikohz
Copy link

kikohz commented Mar 7, 2024

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.
My solution is:
add in the ssr rendered page: export const dynamic = "force-dynamic"; (force use)
Will fix the error, but the page where I used 'use client' didn't work.

@kikohz
Copy link

kikohz commented Mar 7, 2024

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. My solution is: add in the ssr rendered page: export const dynamic = "force-dynamic"; (force use) Will fix the error, but the page where I used 'use client' didn't work.

I solve this problem in my project, add a page to act as a buffer in the components that use 'use client', as show in the picture, page.tsx is the buffer page, p is the original page which use 'use client', the code for page.tsx is very simple:

import GiftCard from './purchase-gift-card'
export const dynamic = "force-dynamic";
export const fetchCache = "force-no-store";
export default function Page(){
    return (<GiftCard />)
}

@pedroSoaresll
Copy link

I am facing this issue, it happens in builds on a local machine but not on Vercel CI. I could not find the reason yet.

image

I am not facing this issue anymore in the latest NextJS version.

image

@zounar
Copy link

zounar commented Mar 12, 2024

After weeks of having this issue, I finally found a solution! 😊

The issue is caused by the fact that I was running next build with NODE_ENV=development. As stated in the documentation, the NODE_ENV must be always set to production when calling next build, regardless of your environment. 🤷

The reason why it worked for many of you in Vercel and not locally is simply that Vercel properly sets NODE_ENV=production variable when building.

Because I was using NODE_ENV in my application to detect the production environment, I had to create a new variable, NEXT_PUBLIC_APP_ENV (development | production), as proposed in the documentation, which now serves such a purpose. 🎉

@sFritsch09
Copy link

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 🚀

@amoore108
Copy link
Author

amoore108 commented Mar 12, 2024

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.

@StarlinMarrero
Copy link

same error on 14.1.3 for us: during the build

ReferenceError: Cannot access 'u' before initialization

@sFritsch09
Copy link

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 😭

@saitharunsai
Copy link

saitharunsai commented Mar 17, 2024

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. 😿

@federicocappellotto97
Copy link

federicocappellotto97 commented Mar 21, 2024

Same here, it builds locally, but when i deploy to azure devops i get:

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

ReferenceError: Cannot access 'u' before initialization
    at Object.ZP (/var/devops/agent08/_work/546/s/frontend/apps/front/.next/server/chunks/418.js:1:685)
    at /var/devops/agent08/_work/546/s/frontend/apps/front/.next/server/chunks/890.js:1:192
    at o.a (/var/devops/agent08/_work/546/s/frontend/apps/front/.next/server/webpack-runtime.js:1:879)
    at 66890 (/var/devops/agent08/_work/546/s/frontend/apps/front/.next/server/chunks/890.js:1:82)
    at Function.o (/var/devops/agent08/_work/546/s/frontend/apps/front/.next/server/webpack-runtime.js:1:128)

i'm using "next": "^14.1.4"

@huozhi
Copy link
Member

huozhi commented Mar 27, 2024

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.

@itsJimmyQ
Copy link

I had encoutered this with every next version starting from 14.0.0.
The error i got was when running npm run build:

ReferenceError: Cannot access 'o' before initialization

This is resolved by locating the circular reference in my import/exports.
Make sure if you are a compound component pattern, or maybe some barrel exports, there's not a infinite circular reference going on, meaning an import that imports a module which imports another module that imports the first module.

@samcarton
Copy link

samcarton commented Apr 4, 2024

We ended up finding a workaround as this was breaking ~50% of our builds and wasting so many build minutes.

  • This is the important part: We added a non-static custom error page. This forces the nextjs build to NOT BUILD STATIC 404 and 500 pages, at least for pages router.
    • This is the only way we could stop these from being generated. Making custom 404 and 500s didn't help.
  • Forced SSR for all our "static" pages (just add a getServerSideProps that returns { props: {} }).
  • So now we have no static pages, but we have a stable build. 🚀

Example pages\_error.tsx page:

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;

@huozhi huozhi added the please add a complete reproduction The issue lacks information for further investigation label Apr 4, 2024
Copy link
Contributor

github-actions bot commented Apr 4, 2024

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 App Router, template for Pages Router), but you can also use these templates: CodeSandbox: App Router or CodeSandbox: Pages 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. Ensure your reproduction does not depend on secrets, 3rd party registries, private dependencies, or any other data that cannot be made public. Avoid a reproduction including a whole monorepo (unless relevant to the issue). The easier it is to reproduce the issue, the quicker we can help.

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

If you cannot create a clean reproduction, another way you can help the maintainers' job is to pinpoint the canary version of next that introduced the issue. Check out our releases, and try to find the first canary release that introduced the issue. This will help us narrow down the scope of the issue, and possibly point to the PR/code change that introduced it. You can install a specific version of next by running npm install next@<version>.

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

@mateuszNadolny
Copy link

Still having this error on Next.js 14.1.3. Workaround with dynamic imports did not help.

@NathanFrank285
Copy link

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

@timneutkens
Copy link
Member

@NathanFrank285 there should be logs though? Please share the entire build logs.

@pablojsx
Copy link

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 .

@FingerLiu
Copy link

In my case, I can build it locally, but can not build it in Docker.
In the end, I found I didn't put pnpm-lock.yaml to Dockerfile, after add this to Dockerfile before pnpm run build, it works fine.
COPY pnpm-lock.yaml ./

@oxuk85
Copy link

oxuk85 commented May 16, 2024

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.

@oxuk85
Copy link

oxuk85 commented May 16, 2024

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

@ariefrahmansyah
Copy link

Adding --prod to vercel build solved my issue. Previously, I had similar errors like others:

> Export encountered errors on following paths:
	/_not-found
	/page: /
	/profile/page: /profile

@jaredterm
Copy link

jaredterm commented May 28, 2024

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. My solution is: add in the ssr rendered page: export const dynamic = "force-dynamic"; (force use) Will fix the error, but the page where I used 'use client' didn't work.

I solve this problem in my project, add a page to act as a buffer in the components that use 'use client', as show in the picture, page.tsx is the buffer page, p is the original page which use 'use client', the code for page.tsx is very simple:

import GiftCard from './purchase-gift-card'
export const dynamic = "force-dynamic";
export const fetchCache = "force-no-store";
export default function Page(){
    return (<GiftCard />)
}

For anyone who is running into this issue using next in conjunction with nx monorepo: This temporary solution works. Proxying client-side pages using this method will ensure the builds succeed correctly.

thanks @kikohz

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. linear: next Confirmed issue that is tracked by the Next.js team. please add a complete reproduction The issue lacks information for further investigation
Projects
None yet
Development

No branches or pull requests