next.js: `dynamicParams=false` show 404 page in dev, but not show 404 page after build in prod

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #22 SMP Tue Jan 10 18:39:00 UTC 2023
    Binaries:
      Node: 16.17.0
      npm: 8.15.0
      Yarn: 1.22.19
      pnpm: 7.1.0
    Relevant Packages:
      next: 13.4.10-canary.8
      eslint-config-next: N/A
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 4.9.5
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

App Router

Link to the code that reproduces this issue or a replay of the bug

https://codesandbox.io/p/sandbox/wandering-forest-3tmmtz

To Reproduce

Run yarn dev, then access https://3tmmtz-3000.csb.app/post/404, it shows 404 page which is expected. Run yarn build, then yarn start in prod mode, access the same url as above, it shows the rendering page, not 404 page.

Describe the Bug

Leaving dynamicParams=false and accessing an entry point that does not exist in generateStaticParams does not return a 404 page in prod. (dev works fine)

The generateStaticParams only returns id 1,2,3 which means all the other param with id should return 404. Seems dev works as expected but prod is not.

Expected Behavior

when access a param that not returned by generateStaticParams function, it should return 404 page in both dev and prod.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Reactions: 11
  • Comments: 18 (4 by maintainers)

Commits related to this issue

Most upvoted comments

This is still a problem today.

I found something interesting more today:

  • when using axios instead of fetch to fetch data, then both dev and prod can work correctly. ✅
  • When using fetch with {next: { revalidate: 0 },}, then dev is working, but prod it not work ❌
  • When using fetch without {next: { revalidate: 0 },}, then both dev and prod can work correctly. ✅

So I believe the problem is because the nextjs fetch cache. If you encounter the similar problem, you can either remove revalidate prop(default revalidate is false) or use other http client to fetch data.

One thing to remember is based on document here: https://nextjs.org/docs/app/api-reference/functions/fetch#revalidate, when using fetch, if we are not setting the revalidate, the default value is false which means there is a force cache happen.

I am using fetch without {next: { revalidate: 0 },} and still have the same issue in Next 14.2.3.

Also facing the same problem with 14.2.3. I’m trying to limit our website to specific languages (example.com/en and example.com/fr), but I can’t get it to consistently throw a 404 for random values.

Also facing the same problem as of today.

▲ Next.js 14.1.0
  - Environments: .env.local

  Creating an optimized production build ...
Compiler edge-server unexpectedly exited with code: null and signal: SIGTERM
✓ Compiled successfully
✓ Linting and checking validity of types    
⚠ Using edge runtime on a page currently disables static generation for that page
✓ Collecting page data
✓ Generating static pages (15/15)
✓ Collecting build traces    
✓ Finalizing page optimization

For me the problem is with Vercel. I have the exact same project on Vercel and Netlify. Netlify returns 404 as expected, Vercel doesn’t. The same code on Vercel: https://keytours-test.vercel.app/en/meteora/shoud-not-work and Netlify: https://keytours-test.netlify.app/en/meteora/shoud-not-work