generate-static-params.mdx


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:

export function generateStaticParams() {
  return [{ slug: 'first-post' }, { slug: 'second-post' }]
}

See the generateStaticParams return value documentation for the expected shape.

With ensureStatic

A dynamic route that uses ensureStatic = 'navigation' must export generateStaticParams and return at least one params object. Every object must include a value for each dynamic segment in the route.

export const ensureStatic = 'navigation'

export function generateStaticParams() {
  return [{ slug: 'first-post' }, { slug: 'second-post' }]
}

If the route must accept values that cannot be listed at build time, first confirm that request-time rendering is intended for the entire route. Then remove ensureStatic = 'navigation' from every page or layout that sets it. Removing the export relaxes the static-output requirement for every segment in the route.

Using output: 'export'

When your application uses output: 'export', every Dynamic Route, 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.

Rendered from the public repository vercel/next.js on GitHub; content belongs to its authors. Cached for up to an hour.

errors/generate-static-params.mdx · vercel/next.js | Docs MD