Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

next build with output: 'export' fails on a dynamic route

Errormissing "generateStaticParams()" with output: export

Short answer

A static export has to know every URL at build time. A dynamic route such as app/blog/[slug] needs generateStaticParams to return the slugs, and dynamicParams must not stay true. Add the function, return one object per page, and keep features that need a server out of the exported app.

  • Applies to Next.js 15, Next.js 16, App Router
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Check the export setting and list your dynamic route folders. Every folder with square brackets needs its own list of params.

    grep -n "output" next.config.*
    find app -type d -name "\[*\]"
  2. 2Match what you see, then jump to its fix

    1. 1The error names a route such as /blog/[slug]The dynamic route has no generateStaticParamsFix
    2. 2The function exists but the build still rejects the routedynamicParams is true, so unknown URLs would need a serverFix
    3. 3The error points to an app/api route, cookies(), rewrites, redirects or headersA route handler or server feature cannot be computed at build timeFix

What does the error look like?

  • missing "generateStaticParams()" with output: export
  • Nextjs isn't building with output: export

Cause 1 of 3

The dynamic route has no generateStaticParams

1Check

Dynamic routes without generateStaticParams are listed by Next.js as unsupported in a static export.

grep -rn "generateStaticParams" app

2Fix

Export generateStaticParams from the page. Return an array with one object per page, using the segment name as key.

// app/blog/[slug]/page.js
export async function generateStaticParams() {
  const posts = await fetch('https://api.example.com/posts').then((r) => r.json())
  return posts.map((post) => ({ slug: post.slug }))
}

3Verify

Build again. Next.js writes one HTML file per returned slug into out/.

npm run build
ls out/blog

Confirmed by nextjs.org

Did this fix it?

Cause 2 of 3

dynamicParams is true, so unknown URLs would need a server

1Check

Dynamic routes with dynamicParams: true are unsupported in a static export, because a URL that was not generated would have to be rendered on request.

grep -rn "dynamicParams" app

2Fix

Set dynamicParams to false in that segment. Paths you did not return then answer 404.

// app/blog/[slug]/page.js
export const dynamicParams = false

3Verify

Build again and open an exported page.

npm run build

Confirmed by nextjs.org

Did this fix it?

Cause 3 of 3

A route handler or server feature cannot be computed at build time

1Check

A static export cannot use cookies, rewrites, redirects, headers, Server Actions or route handlers that read the request. A GET handler must be marked static so it can be rendered during the build.

grep -rln "cookies()\|rewrites\|redirects\|use server" app next.config.*

2Fix

Mark a handler that needs no request data as static. Move anything that truly needs a server to an API outside this app, or stop using output: 'export'.

// app/data.json/route.js
export const dynamic = 'force-static'

export async function GET() {
  return Response.json({ name: 'Lee' })
}

3Verify

The build writes data.json into out/.

npm run build && ls out/data.json

Confirmed by nextjs.org

Did this fix it?

How do I stop it coming back?

  • Decide on a static export at the start and test next build in CI, since the features it cannot use are easy to add by accident.
  • Keep the list of slugs in one function used by both generateStaticParams and the sitemap.
  • Move login and other request-time work to a separate service.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.