Files
vercel__next.js/errors/generate-static-params.mdx
Jiwon Choi f2e6abb47e Throw for empty or incomplete generateStaticParams results with output: export (#95969)
> [!TIP]
> This PR is best reviewed commit by commit.

### Why?

With `output: 'export'`, an empty array or incomplete params can be
reported as a missing `generateStaticParams` function, even when the
function exists.

### How?

- Throw when any `generateStaticParams` invocation returns `[]`.
- Throw when any composed parent and child params object omits a dynamic
route parameter.
- Extend the troubleshooting page added in #95968 with the
export-specific cases.

Stacked on #95968.

Supersedes #95388.

<!-- NEXT_JS_LLM -->

Co-authored-by: SukkaW <isukkaw@gmail.com>
2026-07-23 23:25:55 +02:00

45 lines
2.0 KiB
Plaintext

---
title: '`generateStaticParams` Error'
---
## Why This Error Occurred
Next.js expects `generateStaticParams` to return an array containing one params object for each route to generate.
This error occurs when:
- `generateStaticParams` returns a value that is not an array, or
- an item in the returned array is not a plain object. This includes `null`, arrays, primitive values, and `undefined`.
## Possible Ways to Fix It
Return an array of params objects from `generateStaticParams`:
```tsx filename="app/blog/[slug]/page.tsx"
export function generateStaticParams() {
return [{ slug: 'first-post' }, { slug: 'second-post' }]
}
```
See the [`generateStaticParams` return value documentation](/docs/app/api-reference/functions/generate-static-params#returns) for the expected shape.
## Using `output: 'export'`
When your application uses `output: 'export'`, every [Dynamic Route](/docs/app/api-reference/file-conventions/dynamic-routes), such as `app/blog/[slug]/page.tsx`, must be rendered at build time.
This error also occurs when a dynamic route:
- does not export a `generateStaticParams` function,
- returns an empty array from `generateStaticParams`, or
- generates a route without every dynamic route parameter. For example, `{ slug: 'first' }` does not provide the `id` value for a route using an `[id]` segment.
When multiple route segments export `generateStaticParams`, Next.js combines the params returned by each parent and child function before generating routes.
Export `generateStaticParams` from every dynamic route and make sure the combined params include all dynamic route parameters for every generated route. If the paths cannot be known at build time, remove `output: 'export'` from your Next.js configuration.
## Useful Links
- [`generateStaticParams` documentation](/docs/app/api-reference/functions/generate-static-params)
- [Static Exports documentation](/docs/app/guides/static-exports)
- [Dynamic Routes documentation](/docs/app/api-reference/file-conventions/dynamic-routes)