next build with output: 'export' fails on a dynamic route
missing "generateStaticParams()" with output: exportShort 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.
Fix it fast
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 "\[*\]"2Match what you see, then jump to its fix
- 1
The error names a route such as /blog/[slug]The dynamic route has no generateStaticParamsFix - 2
The function exists but the build still rejects the routedynamicParams is true, so unknown URLs would need a serverFix - 3
The error points to an app/api route, cookies(), rewrites, redirects or headersA route handler or server feature cannot be computed at build timeFix
- 1
What does the error look like?
missing "generateStaticParams()" with output: exportNextjs 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" app2Fix
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/blogConfirmed by nextjs.org
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" app2Fix
Set dynamicParams to false in that segment. Paths you did not return then answer 404.
// app/blog/[slug]/page.js
export const dynamicParams = false3Verify
Build again and open an exported page.
npm run buildConfirmed by nextjs.org
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.jsonConfirmed by nextjs.org
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
Servers
A Next.js static export works by clicking links but gives 404 on refresh or deep links
The home page loads, but a direct link to /blog/post-1 returns 404
A static export writes one HTML file per route, such as about.html.
3 causes, each with a fixWeb apps
AuthUserPoolException: Auth UserPool not configured in a Next.js app
Auth UserPool not configured
The error means an Amplify Auth call ran before Amplify.configure did.
3 causes, each with a fixWeb apps
Apollo Server rejects a request as a potential CSRF
HTTP 400 Bad Request from the GraphQL endpoint
Apollo Server's CSRF prevention is on by default.
3 causes, each with a fixWeb apps
Clerk cannot read its publishable key in a Next.js app
NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY is undefined
Clerk reads NEXT_PUBLIC_CLERK_PUBLISHABLE_KEY.
3 causes, each with a fixWeb apps
The shell cannot find create-next-app
command not found: create-next-app
create-next-app is not meant to be installed as a shell command.
2 causes, each with a fixWeb apps
ESLint fails with: Cannot find module 'next/babel'
ESLint stops on the first file with a Babel or parser error instead of listing lint results
next/babel is a Babel preset that ships inside the next package.
3 causes, each with a fix