8000 allow empty array for generateStaticParams · Issue #61213 · vercel/next.js · GitHub
[go: up one dir, main page]

Skip to content

allow empty array for generateStaticParams #61213

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
barroudjo opened this issue Jan 26, 2024 · 8 comments · May be fixed by #62108
Open

allow empty array for generateStaticParams #61213

barroudjo opened this issue Jan 26, 2024 · 8 comments · May be fixed by #62108
Labels
bug Issue was opened via the bug report template.

Comments

@barroudjo
Copy link

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 #58171 and #57996 are related.

@barroudjo barroudjo added the bug Issue was opened via the bug report template. label Jan 26, 2024
@rogermparent rogermparent linked a pull request Feb 15, 2024 that will close this issue
@enricoros
Copy link
enricoros commented Feb 18, 2024

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.

enricoros added a commit to enricoros/big-AGI that referenced this issue Feb 18, 2024
This introduces a pre-build step on Next Build, which hides the files
in the app/api directory when the EXPORT_FRONTEND environment
variable is true-ish.

Hopefully there won't be disruption due to the post-processing step.

Also check vercel/next.js#61213 for
upstream updates.
ericanastas added a commit to ericanastas/ericanastas.com that referenced this issue Apr 12, 2024
@useEffects

This comment has been minimized.

@kaushal-stere
Copy link

Has this been fixed yet?

@albertdugba
Copy link

I'm also experiencing this issue

@shaneheyworth
Copy link

I am also experiencing this issue

@shaneheyworth
Copy link

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

jack482653 added a commit to jack482653/swconf2024 that referenced this issue Nov 2, 2024
jack482653 added a commit to sciwork/swconf2024 that referenced this issue Nov 2, 2024
* build: update @tailwindcss/typography -> 0.5.15

* fix: fix tailwindcss auto order

* fix: add typography

* feat: add home page

* feat: complete welcome page

* refactor: remove unused css

* fix: add @types/js-cookie

* fix: workaround build failed when generateStaticParams() return []

issue: vercel/next.js#61213
jack482653 added a commit to sciwork/swconf2024 that referenced this issue Nov 2, 2024
* Change base font size

1 rem = 10 px. Origin is 1 rem = 16 px. For easily calculating

* Implement the hero section view

* Fix build error

* Solve gray space

* Ignore yarn builded files

* feat: home page (#2)

* build: update @tailwindcss/typography -> 0.5.15

* fix: fix tailwindcss auto order

* fix: add typography

* feat: add home page

* feat: complete welcome page

* refactor: remove unused css

* fix: add @types/js-cookie

* fix: workaround build failed when generateStaticParams() return []

issue: vercel/next.js#61213

---------

Co-authored-by: 鄭宇伸 <timmyabc10@gmail.com>
@nfroidure
Copy link
Contributor

Returning an empty array is legit in some cases like here for pagination to point out the fact there is no page 2 and still avoid to create a /blog/page-1 that would be a duplicate of /blog:
https://github.com/nfroidure/politics/blob/ce48071888350da740ffd1a10c8662703445b8bb/src/app/blog/pages/%5Bpage%5D/page.tsx#L37

@amrtaher1234
Copy link

How is this not fixed till now?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Issue was opened via the bug report template.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

8 participants
0