next.js: Error occurred prerendering page "/_not-found" with pageExtensions option
Link to the code that reproduces this issue
https://codesandbox.io/p/devbox/misty-glade-yh92cc
To Reproduce
After update to 14.2.* version, when i use pageExtensions in next.config, i got an error while try to build my app
module.exports = {
pageExtensions: ['page.tsx', 'page.ts'],
}
i have in my app folder all files with .page.tsx -
app:
- error.page.tsx
- global-error.page.tsx
- not-found.page.tsx
- layout.page.tsx
- page.page.tsx
Current vs. Expected behavior
Build app fail with pageExtentions option
✓ Linting and checking validity of types
✓ Collecting page data
Generating static pages (0/8) [= ]
Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
TypeError: Cannot read properties of undefined (reading 'clientModules')
at /home/ui/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:16:23603
at /home/ui/node_modules/next/dist/server/lib/trace/tracer.js:191:62
at /home/ui/node_modules/next/dist/server/lib/trace/tracer.js:140:36
at NoopContextManager.with (/home/ui/node_modules/@opentelemetry/api/build/src/context/NoopContextManager.js:25:19)
at ContextAPI.with (/home/node_modules/@opentelemetry/api/build/src/api/context.js:60:46)
at NoopTracer.startActiveSpan (/home/ui/node_modules/@opentelemetry/api/build/src/trace/NoopTracer.js:65:31)
at ProxyTracer.startActiveSpan (/home/ui/node_modules/@opentelemetry/api/build/src/trace/ProxyTracer.js:36:24)
at /home/ui/node_modules/next/dist/server/lib/trace/tracer.js:122:103
at NoopContextManager.with (/home/ui/node_modules/@opentelemetry/api/build/src/context/NoopContextManager.js:25:19)
at ContextAPI.with (/home/ui/node_modules/@opentelemetry/api/build/src/api/context.js:60:46)
✓ Generating static pages (8/8)
> Export encountered errors on following paths:
/_not-found/page: /_not-found
Provide environment information
Operating System:
Platform: linux
Arch: x64
Version: #29~22.04.1-Ubuntu SMP PREEMPT_DYNAMIC Thu Apr 4 14:39:20 UTC 2
Available memory (MB): 15622
Available CPU cores: 12
Binaries:
Node: 20.12.2
npm: 10.5.0
Yarn: 1.22.19
pnpm: N/A
Relevant Packages:
next: 14.2.3 // Latest available version is detected (14.2.3).
eslint-config-next: 14.2.3
react: 18.2.0
react-dom: 18.2.0
typescript: 5.4.5
Next.js Config:
output: N/A
Which area(s) are affected? (Select all that apply)
Not sure
Which stage(s) are affected? (Select all that apply)
next build (local)
Additional context
No response
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 32
- Comments: 65
Commits related to this issue
- fix next js build issue https://github.com/vercel/next.js/issues/65447#issuecomment-2294801418 — committed to aadityamayankar/macra-fe by aadityamayankar 2 years ago
- fix: next.js not-found issue - reference: https://github.com/vercel/next.js/issues/65447 — committed to gsahadevan/gsahadevan.github.io by gsahadevan 2 years ago
From my research, it seems that the only workaround is to use “not-found.ts” or “not-found.tsx”.
Briefly, the workaround is to use the file
not-found.tsinstead ofnot-found<pageExtensions>even when using custom pageExtensions."ts"to"pageExtensions"optionnot-found.tsinstad ofnot-found<pageExtensions>file📝 Probably, You can also work around this by using
pageExtensions: [... "tsx"]andnot-found.tsx. However, users of pageExtensions will want to avoid the combination ofpageExtensions: [“page.tsx”, “tsx”][^1], so the example is written withpageExtensions: [..., "ts"].Example:
This example is based on @riccardolardi reproduce repo
However, I believe this behavior is a bug because it is inconsistent. I expect it to be corrected for this reason.
[^1]: The combination of “page.tsx” and “tsx” is likely to generate a “Duplicate page detected.” warning, and I not want to specify these into the
pageExtensionsoption at the same time.experiencing same issue after upgrade to 15-rc
guys i spent an hour on this bug
my issue was that i didn’t have my ENVs set up in vercel
leaving this here in case it helps someone
I have the same issue, builds fine locally but on Vercel I get this error:
The build works but then all my pages starts throwing 404 not found 😕
I also had this issue and i think i managed to fix it this morning. I’m using next-intl as well (like few other people here) and fix for me was turning not-found.tsx page into server component and adding “force-dynamic” on top:
I also added
unstable_setRequestLocale(params.locale);to all layout and page components which are server components. That alone didn’t help, but the above mentioned solution did. Hope it helps someone!My next.config.mjs file looks like this:
Another thing I found — after running a build, looking at the
.next/app-paths-manifest.jsonfile, I see an entry for"/_not-found/page": "app/_not-found/page.js". I also noticed that for every other entry in there, there is a corresponding<bundlename>-client-reference-manifest.js, but this file is missing for the not-found page.I’m guessing that this missing file corresponds to an undefined
clientReferenceManifestI mentioned in my last comment.When I downgrade to v14.1.4, I see a couple of differences:
.next/server/app/_not-found.js(instead of.next/server/app/_not-found/page.jsin v14.2.3).next/server/app/_not-found_client-reference-manifest.jsexistsI now think this bug was caused by https://github.com/vercel/next.js/pull/62679
I was able to fix this issue by padding in pageExtension to the nextConfig.
Here’s my full
next.config.tsUsing “next”: “15.3.0-canary.31” btw
This first seemed to work as a workaround for me, but then I ran into other issues. The final solution for my problem was this: https://github.com/wpengine/faustjs/issues/361#issuecomment-885017853 I’m using next v15.3.0 and app routing.
I found a fix that worked for me. If you’re using i18Next for translation make sure the provider is on the client side
change my import from : import { I18nextProvider } from “react-i18next”;
to: const I18nextProvider = dynamic( () => import(“react-i18next”).then((mod) => mod.I18nextProvider), { ssr: false, } );
and it fixed my issue
Alright i think i found the issue. What worked for me so far was to rename the default function in this file
/src/app/not-found.tsxfromNotFoundPagetoNotFoundI thought this had solved my building issue, as in the fact the build finishes successfully. However, if I try to run that build locally (or deploy it), all routes render the default 404 not found page.
If I remove that
next.config.mjsfix, I can run my app flawlessly, but then again, I can’t build it.Without next.config.mjs patch
runtime ✅ build ❌
With next.config.mjs patch
Current folder structure
runtime ✅ build ❌Did anyone actually overcome this issue?
Downgraded to 14.1.4 from my package.json, and I can confirm I no longer see the following error:
What worked for me was using my .env file instead of .env.local. At first I had only .env.local where all my variables were, but then I made .env and placed my variables in that. Now it builds fine.
My version of Nexjts is 15.3.1 plus I am also using supabase too
"@supabase/ssr": "^0.5.2","@supabase/supabase-js": "^2.50.0",Same here, I’m now able to make it work with node v22.14.0 with the
pageExtensionssolution, as @kaisewhite suggestednode v22.14.0 may produce this error while v20.14.0 can build successfully.
I’m using the following dependencies in my Next.js project:
"next": "15.1.0""react": "^19.0.0"pnpm 9.3.0I ran
pnpm buildbut can confirm that the issue still persists.Project Setup
page.tsx
next.config.mjs
Additional Debugging Steps Taken
I have tried the following but the issue remains:
output: 'standalone'tonextConfigexport const dynamic = 'force-dynamic'topage.tsxDespite these adjustments, the error persists during the build process. Any insights or suggestions would be greatly appreciated.
@ericpark11 - Did you ever find a solution to this? I just installed next-intl into a new project and am facing the same issue. Thanks.
Downgrading to the latest version of Next 14 (from Next 15) completely fixed things for me.
I faced this while using
next-authand not providingNEXTAUTH_URLenv. Local build was working fine, but the Vercel cloud build was failing. Resolved after setting this environment variable.Details on https://next-auth.js.org/configuration/options.
We faced the issue because we used i18n / react-intl to have a localized not found page. Removal of the localization solved this issue for us.
This issue also can happen when you have circular dependencies in the code even if you don’t have
not-foundpage in the codebase, the error still references/_not-found.Yes, but no page extensions
I’m using latest 14
I think my problem was that I was having page.tsx inside an
(index)folder. Taking it out there solved the issue if I remember correctly