vercel / next.js

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

allow empty array for generateStaticParams #61213

Open barroudjo opened 9 months ago

barroudjo commented 9 months ago

Link to the code that reproduces this issue

https://codesandbox.io/p/devbox/compassionate-wilson-qcxws4?file=%2Fapp%2Ffoo%2F%5Bslug%5D%2Fpage.tsx%3A12%2C47

To Reproduce

  1. See that the file in app/foo/[slug]/page.tsx has a generateStaticParams function that returns an empty array, and there are two possible ways to build the app, one with output: 'export' (npm run build:export) and one with output: undefined (npm run build:ssr)
  2. Try npm run build:export and see that it fails with the error message:
    Error: Page "/foo/[slug]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.

Current vs. Expected behavior

It is a real use case of Next.js to have two ways of running the same codebase: one in SSR mode (output: undefined) for users of the CMS (that the Next.js app is connected to) to be able to use the draft mode and preview their work, and one in SSG mode (output: 'export') that is used for production, by just hosting its output on a CDN.

Current Behavior

If a page.tsx has a generateStaticParams function that returns an empty array (for example because the writers are working on unpublished documents on the CMS, only available through the draft mode in SSR), then the same codebase cannot be used for a production SSG build as it will crash when building with output: 'export' ! This is problematic.

Expected behavior

There should be a way to allow SSG builds (with output: 'export') to proceed even if a page.tsx has a generateStaticParams function that returns an empty array.

Provide environment information

Operating System:
  Platform: linux
  Arch: x64
  Version: #1 SMP PREEMPT_DYNAMIC Sun Aug  6 20:05:33 UTC 2023
Binaries:
  Node: 20.9.0
  npm: 9.8.1
  Yarn: 1.22.19
  pnpm: 8.10.2
Relevant Packages:
  next: 14.1.1-canary.13 // Latest available version is detected (14.1.1-canary.13).
  eslint-config-next: N/A
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.1.3
Next.js Config:
  output: export

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

App Router, Static HTML Export (output: "export")

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

next build (local)

Additional context

I'm fairly sure the problem was already present in version 13.4. Issues https://github.com/vercel/next.js/issues/58171 and https://github.com/vercel/next.js/issues/57996 are related.

enricoros commented 9 months ago

Same issue here, thanks @rogermparent, can't wait for this to land. Cannot proceed in any way: I need to delete my /api/name/[slug]/route.ts file before the export.

useEffects commented 4 months ago

+1

Edit by maintainer bot: Comment was automatically minimized because it was considered unhelpful. (If you think this was by mistake, let us know). Please only comment if it adds context to the issue. If you want to express that you have the same problem, use the upvote 👍 on the issue description or subscribe to the issue for updates. Thanks!

kaushal-stere commented 1 month ago

Has this been fixed yet?

albertdugba commented 1 month ago

I'm also experiencing this issue

shaneheyworth commented 3 weeks ago

I am also experiencing this issue

shaneheyworth commented 3 weeks ago

To everyone above me, it's fucking STUPID but looks like if you "return [{ slug: 'test'}]" it will build