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

Error with generateStaticParams function despite its existence #57038

Closed
1 task done
k-taro56 opened this issue Oct 19, 2023 · 4 comments · Fixed by #57053
Closed
1 task done

Error with generateStaticParams function despite its existence #57038

k-taro56 opened this issue Oct 19, 2023 · 4 comments · Fixed by #57053
Labels
linear: next Confirmed issue that is tracked by the Next.js team. locked

Comments

@k-taro56
Copy link
Contributor

k-taro56 commented Oct 19, 2023

Link to the code that reproduces this issue

https://github.com/k-taro56/next-bug-report

To Reproduce

Set up Next.js.
Add output: 'export' to next.config.js to enable static output.
Create a page that allows dynamic routing.
Create the generateStaticParams function and make it return an empty array.
Run next build.

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

Current vs. Expected behavior

Current behavior:
An error is raised indicating that the generateStaticParams function does not exist.

Expected Behavior:
The generateStaticParams function should return an array with at least one element.

Verify canary release

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

Provide environment information

Operating System:
  Platform: win32
  Arch: x64
  Version: Windows 11 Home
Binaries:
  Node: 18.18.0
  npm: N/A
  Yarn: N/A
  pnpm: N/A
Relevant Packages:
  next: 13.5.6-canary.7
  eslint-config-next: 13.5.5
  react: 18.2.0
  react-dom: 18.2.0
  typescript: 5.2.2
Next.js Config:
  output: export

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

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

Additional context

No response

NEXT-1951

@k-taro56 k-taro56 added the bug Issue was opened via the bug report template. label Oct 19, 2023
@viktorronnback
Copy link
Contributor

The repro code is missing any returned pages in the generateStaticParams function, for example:

export const generateStaticParams = () => [{ slug: "page" }];

However I agree that the error message is misleading, if a maintainer agrees I could add a PR to improve the error message.

@k-taro56
Copy link
Contributor Author

Thank you for your reply.

I completely agree with your observation regarding the error message.
It would be helpful for others if the error message could be more descriptive or clear about the actual problem.

I would like to submit a PR to improve the error message. Would that be okay?

@styfle styfle added kind: bug linear: next Confirmed issue that is tracked by the Next.js team. and removed bug Issue was opened via the bug report template. labels Jan 2, 2024
styfle added a commit that referenced this issue Jan 4, 2024
…with `output:export` (#57053)

Fixes #57038

# What?
Added an error message when `generateStaticParams` returns an empty
array with `output:export`.

# Why?
To provide developers with clear feedback when `generateStaticParams` is
not used correctly.

# How?
Modified the condition checks around the use of `generateStaticParams`
to include a check for an empty array and added a corresponding error
message.

---------

Co-authored-by: Steven <steven@ceriously.com>
agustints pushed a commit to agustints/next.js that referenced this issue Jan 6, 2024
…with `output:export` (vercel#57053)

Fixes vercel#57038

# What?
Added an error message when `generateStaticParams` returns an empty
array with `output:export`.

# Why?
To provide developers with clear feedback when `generateStaticParams` is
not used correctly.

# How?
Modified the condition checks around the use of `generateStaticParams`
to include a check for an empty array and added a corresponding error
message.

---------

Co-authored-by: Steven <steven@ceriously.com>
@airtonix
Copy link

airtonix commented Jan 11, 2024

@viktorronnback what about when the url looks like:

/keystatic/[...params]

despite my src/app/keystatic/[...params]/page.tsx looking like:

export default function Page() {
    return null;
}

export async function generateStaticParams() {
    return [{ params: [] }]
}

how should I interpret the error:

> Build error occurred
Error: Page "/api/keystatic/[...params]" is missing "generateStaticParams()" so it cannot be used with "output: export" config.

Copy link
Contributor

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 github-actions bot locked as resolved and limited conversation to collaborators Jan 26, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
linear: next Confirmed issue that is tracked by the Next.js team. locked
Projects
None yet
4 participants