Skip to content
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

generateStaticParams with next export: Build fails when generateStaticParams returns an empty array of params #71862

Open
NasserBvB opened this issue Oct 25, 2024 · 2 comments
Labels
bug Issue was opened via the bug report template. create-next-app Related to our CLI tool for quickly starting a new Next.js application. Output (export/standalone) Related to the the output option in `next.config.js`. Script (next/script) Related to Next.js Script Optimization.

Comments

@NasserBvB
Copy link

Link to the code that reproduces this issue

https://github.com/NasserBvB/generate-static-params-issue

To Reproduce

While building a Next.js application with output: "export" in next.config.js, I encountered an error regarding the missing generateStaticParams() function, despite it being implemented and returning an empty list. This error specifically affects dynamic pages in the project.

Notably, the build succeeds as expected when generateStaticParams() returns at least one article parameter in the list. The issue only arises when it returns an empty list ([]).

Steps to Reproduce

  1. Create a new Next.js application using [email protected].
  2. Add a dynamic page at articles/[article]/page.js.
  3. Implement generateStaticParams in articles/[article]/page.js and set it to return an empty list ([]).
  4. Configure output: "export" in next.config.js.
  5. Run the build command.

Expected Behavior

The build should succeed without any issues, recognizing that generateStaticParams() is implemented and returning an empty list of article slugs.

Actual Behavior

An error occurs during the build, specifically stating:

Error: Page "/articles/[article]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.

However, when generateStaticParams() returns a list with at least one article slug, the build completes successfully as expected.

Additional Context

  • I’ve confirmed that generateStaticParams() exists in articles/[article]/page.js, and the issue persists only when it returns an empty list.

Current vs. Expected behavior

Expected Behavior

The build should succeed without any issues, recognizing that generateStaticParams() is implemented and returning an empty list of article slugs.

Actual Behavior

An error occurs during the build, specifically stating:

Error: Page "/articles/[article]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.

However, when generateStaticParams() returns a list with at least one article slug, the build completes successfully as expected.

Provide environment information

Operating System:
  Platform: darwin
  Arch: arm64
  Version: Darwin Kernel Version 24.0.0: Tue Sep 24 23:36:26 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T8103
  Available memory (MB): 16384
  Available CPU cores: 8
Binaries:
  Node: 18.19.0
  npm: 10.2.3
  Yarn: 1.22.22
  pnpm: 9.12.0
Relevant Packages:
  next: 14.2.8 // An outdated version detected (latest is 15.0.1), upgrade is highly recommended!
  eslint-config-next: 14.2.8
  react: 18.3.1
  react-dom: 18.3.1
  typescript: 5.5.4
Next.js Config:
  output: export

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

create-next-app, Output (export/standalone), Script (next/script)

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

next build (local)

Additional context

No response

@NasserBvB NasserBvB added the bug Issue was opened via the bug report template. label Oct 25, 2024
@github-actions github-actions bot added create-next-app Related to our CLI tool for quickly starting a new Next.js application. Output (export/standalone) Related to the the output option in `next.config.js`. Script (next/script) Related to Next.js Script Optimization. labels Oct 25, 2024
@Riley1101
Copy link

Riley1101 commented Oct 25, 2024

Hey @NasserBvB , I take a look at the issue. Looks like you will have to return article in the param object since your dynamic path is /article/[article]/page.tsx.

Take a look at here: https://github.com/NasserBvB/generate-static-params-issue/blob/25021349b5e2430bdc72fab2c0764dff50084448/src/app/articles/%5Barticle%5D/page.tsx#L25C1-L27C7

export async function generateStaticParams() {
  const posts = await mockArticles();

  return posts.map((post) => ({
    slug: post.title, // <- slug should be article
  }));
}

@NasserBvB
Copy link
Author

Yes you are right but even though you correct it you will still get the same thing

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. create-next-app Related to our CLI tool for quickly starting a new Next.js application. Output (export/standalone) Related to the the output option in `next.config.js`. Script (next/script) Related to Next.js Script Optimization.
Projects
None yet
Development

No branches or pull requests

2 participants