next.js icon indicating copy to clipboard operation
next.js copied to clipboard

Global `not-found` page interferes with static rendering

Open amannn opened this issue 1 year ago • 1 comments

Link to the code that reproduces this issue

https://github.com/amannn/nextjs-bug-repro-not-found

To Reproduce

  1. Clone https://github.com/amannn/nextjs-bug-repro-not-found
  2. Run pnpm i
  3. Run pnpm build

Current vs. Expected behavior

This commit outlines the issue: f5cbf18

The not-found page is dynamic, while / is expected to render statically. However, somehow the global not found page is rendered as part of /.

Output:

  ▲ Next.js 15.0.1-canary.1

   Creating an optimized production build ...

warn - No utility classes were detected in your source files. If this is unexpected, double-check the `content` option in your Tailwind CSS configuration.
warn - https://tailwindcss.com/docs/content-configuration
 ✓ Compiled successfully
 ✓ Linting and checking validity of types    
 ✓ Collecting page data    
   Generating static pages (0/4)  [==  ]
Error occurred prerendering page "/". Read more: https://nextjs.org/docs/messages/prerender-error

Error: Route / with `dynamic = "error"` couldn't be rendered statically because it used `headers`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering
Export encountered an error on /page: /, exiting the build.
 ⨯ Static worker exited with code: 1 and signal: null
   Generating static pages (1/4)  [    ] ELIFECYCLE  Command failed with exit code 1.

I'd expect the 404 page to be dynamic while the home page is static.

Provide environment information

Operating System:
  Platform: darwin
  Arch: x64
  Version: Darwin Kernel Version 23.6.0: Mon Jul 29 21:13:00 PDT 2024; root:xnu-10063.141.2~1/RELEASE_X86_64
  Available memory (MB): 16384
  Available CPU cores: 12
Binaries:
  Node: 20.11.1
  npm: 10.2.4
  Yarn: 1.22.22
  pnpm: 9.12.2
Relevant Packages:
  next: 15.0.1-canary.1 // Latest available version is detected (15.0.1-canary.1).
  eslint-config-next: 15.0.1-canary.1
  react: 19.0.0-rc-69d4b800-20241021
  react-dom: 19.0.0-rc-69d4b800-20241021
  typescript: 5.6.3
Next.js Config:
  output: N/A

Which area(s) are affected? (Select all that apply)

Output (export/standalone), Runtime

Which stage(s) are affected? (Select all that apply)

next build (local)

Additional context

No response

amannn avatar Oct 22 '24 11:10 amannn

71623

095osvaldo avatar Oct 23 '24 09:10 095osvaldo

@amannn Thank you for submitting an issue!

Can confirm this is still an issue. We will be taking a look—

samcx avatar Mar 22 '25 22:03 samcx

If you're using next 15.4 or any canary versions above, you can try experimental.globalNotFound and extend not-found.tsx to a standalone page global-not-found.tsx then it can be resolved. You'll have a dynamic 404 page and static index page.

huozhi avatar Jul 16 '25 21:07 huozhi

This closed issue has been automatically locked because it had no new activity for 2 weeks. If you are running into a similar issue, please create a new issue with the steps to reproduce. Thank you.

github-actions[bot] avatar Jul 31 '25 00:07 github-actions[bot]