vercel / next.js

The React Framework
https://nextjs.org
MIT License
122.21k stars 26.17k forks source link

Error occurred prerendering page "/_not-found" with pageExtensions option #65447

Open Krasnopir opened 1 month ago

Krasnopir commented 1 month ago

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

sergejreznik commented 1 month ago

I have suddenly the same error. There were no changes made and this error happens when deploying the application. Build locally works fine, vercel deploy throws this error.


TypeError: Cannot read properties of null (reading 'auth')
--
16:38:14.053 | at a (/vercel/path0/.next/server/chunks/625.js:6:215122)
16:38:14.053 | at O (/vercel/path0/.next/server/chunks/625.js:6:174074)
16:38:14.053 | at /vercel/path0/.next/server/chunks/625.js:6:175009
16:38:14.053 | at Object.nr [as useMemo] (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:39088)
16:38:14.053 | at t.useMemo (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:106635)
16:38:14.053 | at /vercel/path0/.next/server/chunks/625.js:6:174977
16:38:14.053 | at nP (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:58441)
16:38:14.053 | at n$ (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:61978)
16:38:14.053 | at nE (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:44877)
16:38:14.053 | at nP (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:58448)
16:38:14.105 |  
16:38:14.105 | Error occurred prerendering page "/_not-found". Read more: https://nextjs.org/docs/messages/prerender-error
16:38:14.105 | TypeError: Cannot read properties of null (reading 'auth')
16:38:14.105 | at a (/vercel/path0/.next/server/chunks/625.js:6:215122)
16:38:14.105 | at O (/vercel/path0/.next/server/chunks/625.js:6:174074)
16:38:14.105 | at /vercel/path0/.next/server/chunks/625.js:6:175009
16:38:14.106 | at Object.nr [as useMemo] (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:39088)
16:38:14.106 | at t.useMemo (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:106635)
16:38:14.106 | at /vercel/path0/.next/server/chunks/625.js:6:174977
16:38:14.106 | at nP (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:58441)
16:38:14.106 | at n$ (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:61978)
16:38:14.109 | at nE (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:44877)
16:38:14.109 | at nP (/vercel/path0/node_modules/next/dist/compiled/next-server/app-page.runtime.prod.js:12:58448)
16:38:14.536 | Generating static pages (11/44)
16:38:18.106 | Generating static pages (22/44)
16:38:20.328 | Generating static pages (33/44)
16:38:21.301 | ✓ Generating static pages (44/44)
16:38:21.311 |  
16:38:21.313 | > Export encountered errors on following paths:
16:38:21.313 | /_not-found
awmottaz commented 1 month ago

I went spelunking in the code, and this looks suspicious to me:

https://github.com/vercel/next.js/blob/c1f8d9317588e51a8a31240f6add36b5f2c9f9bf/packages/next/src/server/app-render/app-render.tsx#L693-L694

This non-null assertion means clientReferenceManifest could actually be null or undefined and TypeScript won't check it. If it's undefined, you'll get the TypeError: Cannot read properties of undefined (reading 'clientModules') on, say, line 946:

https://github.com/vercel/next.js/blob/c1f8d9317588e51a8a31240f6add36b5f2c9f9bf/packages/next/src/server/app-render/app-render.tsx#L944-L951

My guess is that this issue was introduced here: https://github.com/vercel/next.js/pull/64313

But I definitely don't have enough knowledge or context to confirm that or offer a suggestion on how to fix this

awmottaz commented 1 month ago

Another thing I found — after running a build, looking at the .next/app-paths-manifest.json file, 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.

# notice that a file shows up for every page entry
# but is missing for the not-found page
find .next/ -path '*client-reference-manifest.js'

I'm guessing that this missing file corresponds to an undefined clientReferenceManifest I mentioned in my last comment.

When I downgrade to v14.1.4, I see a couple of differences:


I now think this bug was caused by https://github.com/vercel/next.js/pull/62679

awmottaz commented 1 month ago

Maybe this if statement evaluates to false when using page extensions?

https://github.com/vercel/next.js/blob/c1f8d9317588e51a8a31240f6add36b5f2c9f9bf/packages/next/src/build/webpack/plugins/flight-client-entry-plugin.ts#L349-L352

awmottaz commented 1 month ago

Here's a minimal reproduction https://github.com/awmottaz/next-typeerror-not-found

riccardolardi commented 4 weeks ago

I have the same issue, builds fine locally but on Vercel I get this error:

[20:37:58.035] Running build in Washington, D.C., USA (East) – iad1
[20:37:59.058] Cloning github.com/riccardolardi/maybeparis-next (Branch: main, Commit: 2875c34)
[20:37:59.894] Cloning completed: 835.705ms
[20:38:04.646] Restored build cache
[20:38:04.883] Running "vercel build"
[20:38:05.934] Vercel CLI 34.1.10
[20:38:06.673] Installing dependencies...
[20:38:07.448] yarn install v1.22.19
[20:38:07.646] [1/4] Resolving packages...
[20:38:08.138] [2/4] Fetching packages...
[20:38:08.146] warning Pattern ["strip-ansi-cjs@npm:strip-ansi@^6.0.1"] is trying to unpack in the same destination "/vercel/.cache/yarn/v6/npm-strip-ansi-cjs-6.0.1-9e26c63d30f53443e9489495b2105d37b67a85d9-integrity/node_modules/strip-ansi-cjs" as pattern ["strip-ansi@^6.0.1"]. This could result in non-deterministic behavior, skipping.
[20:38:08.146] warning Pattern ["string-width@^4.1.0"] is trying to unpack in the same destination "/vercel/.cache/yarn/v6/npm-string-width-cjs-4.2.3-269c7117d27b05ad2e536830a8ec895ef9c6d010-integrity/node_modules/string-width-cjs" as pattern ["string-width-cjs@npm:string-width@^4.2.0"]. This could result in non-deterministic behavior, skipping.
[20:38:08.146] warning Pattern ["strip-ansi@^6.0.0"] is trying to unpack in the same destination "/vercel/.cache/yarn/v6/npm-strip-ansi-cjs-6.0.1-9e26c63d30f53443e9489495b2105d37b67a85d9-integrity/node_modules/strip-ansi-cjs" as pattern ["strip-ansi@^6.0.1"]. This could result in non-deterministic behavior, skipping.
[20:38:32.651] [3/4] Linking dependencies...
[20:38:32.652] warning " > urql@4.1.0" has unmet peer dependency "@urql/core@^5.0.0".
[20:38:37.594] [4/4] Building fresh packages...
[20:38:37.611] Done in 30.17s.
[20:38:37.660] Detected Next.js version: 14.2.3
[20:38:37.662] Running "yarn run build"
[20:38:37.869] yarn run v1.22.19
[20:38:37.892] $ next build
[20:38:38.676]   ▲ Next.js 14.2.3
[20:38:38.676] 
[20:38:38.751]    Creating an optimized production build ...
[20:38:52.305]  ✓ Compiled successfully
[20:38:52.306]    Linting and checking validity of types ...
[20:38:59.325]    Collecting page data ...
[20:38:59.842] TypeError [ERR_INVALID_URL]: Invalid URL
[20:38:59.842]     at new NodeError (node:internal/errors:405:5)
[20:38:59.842]     at new URL (node:internal/url:676:13)
[20:38:59.843]     at 6192 (/vercel/path0/.next/server/app/_not-found/page.js:1:4320)
[20:38:59.843]     at t (/vercel/path0/.next/server/webpack-runtime.js:1:128)
[20:38:59.843]     at 338 (/vercel/path0/.next/server/app/_not-found/page.js:1:954)
[20:38:59.843]     at t (/vercel/path0/.next/server/webpack-runtime.js:1:128)
[20:38:59.844]     at n (/vercel/path0/.next/server/app/_not-found/page.js:43:75)
[20:38:59.848]     at /vercel/path0/.next/server/app/_not-found/page.js:43:106
[20:38:59.848]     at t.X (/vercel/path0/.next/server/webpack-runtime.js:1:1206)
[20:38:59.848]     at /vercel/path0/.next/server/app/_not-found/page.js:43:88 {
[20:38:59.848]   input: 'undefined',
[20:38:59.848]   code: 'ERR_INVALID_URL'
[20:38:59.849] }
[20:38:59.849] 
[20:38:59.849] > Build error occurred
[20:38:59.849] Error: Failed to collect page data for /_not-found
[20:38:59.849]     at /vercel/path0/node_modules/next/dist/build/utils.js:1268:15
[20:38:59.849]     at process.processTicksAndRejections (node:internal/process/task_queues:95:5) {
[20:38:59.849]   type: 'Error'
[20:38:59.849] }
[20:38:59.887] error Command failed with exit code 1.
[20:38:59.888] info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.
[20:38:59.927] Error: Command "yarn run build" exited with 1
[20:39:00.377] 
riccardolardi commented 4 weeks ago

Since today the build suddenly succeeds... must've been something related to Vercel?

quantafire commented 4 weeks ago

Since today the build suddenly succeeds... must've been something related to Vercel?

Not Vercel. I'm struggling with local builds and our AWS server is spitting out the same error too

jon-dez commented 1 week ago

Another thing I found — after running a build, looking at the .next/app-paths-manifest.json file, 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.

# notice that a file shows up for every page entry
# but is missing for the not-found page
find .next/ -path '*client-reference-manifest.js'

I'm guessing that this missing file corresponds to an undefined clientReferenceManifest I mentioned in my last comment.

When I downgrade to v14.1.4, I see a couple of differences:

* The not-found page is built to `.next/server/app/_not-found.js` (instead of `.next/server/app/_not-found/page.js` in v14.2.3)

* The file `.next/server/app/_not-found_client-reference-manifest.js` exists

I now think this bug was caused by #62679

Downgraded to 14.1.4 from my package.json, and I can confirm I no longer see the following error:

> Export encountered errors on following paths:
    /_not-found/page: /_not-found
yanv1991 commented 4 days ago

experiencing same issue after upgrade to 15-rc