Next.js "Dynamic server usage: Route couldn't be rendered statically" in CI
Next.js tries to render App Router routes statically by default. Reading per-request data such as headers(), cookies(), or searchParams makes the route inherently dynamic, and the static build reports that it could not be prerendered.
What this error means
next build logs "Dynamic server usage: Route '/api/...' couldn't be rendered statically because it used cookies" or headers, often as a DYNAMIC_SERVER_USAGE error.
Error: Dynamic server usage: Route /profile couldn't be rendered statically
because it used `cookies`. See more info here:
https://nextjs.org/docs/messages/dynamic-server-errorCommon causes
A route reads request-scoped data while being prerendered
Calling cookies(), headers(), or reading searchParams requires a request, which does not exist during static generation.
Next could not infer the route should be dynamic
Without an explicit dynamic marker, Next attempts static rendering and only discovers the request dependency when the code runs.
How to fix it
Mark the route as dynamic
- Decide whether the route truly needs per-request data.
- If it does, export
dynamic = 'force-dynamic'so Next renders it at request time. - Re-run next build to confirm the static attempt no longer runs.
export const dynamic = 'force-dynamic'
// or: export const revalidate = 0Remove the request dependency for truly static pages
If the page does not actually need cookies or headers, drop those calls so it can be prerendered.
How to prevent it
- Mark request-dependent routes dynamic intentionally.
- Keep
cookies()/headers()out of pages meant to be static. - Review the build output table to confirm each route's rendering mode.