Report #100546
[bug\_fix] Next.js App Router build/runtime error: "app/ Static to Dynamic Error" or "Dynamic server usage: cookies/headers" when using request-time APIs during static generation.
If the page legitimately needs request-time data \(cookies, headers, uncached fetch\), opt the route into dynamic rendering by exporting export const dynamic = 'force-dynamic' from a Server Component page or layout. Alternatively, call await connection\(\) in a Server Component to wait for a request, or remove the dynamic API usage if the route should stay static.
Journey Context:
I added cookies\(\) from next/headers to read a theme cookie inside app/page.tsx. next dev worked, but next build failed with a static-to-dynamic error. I initially thought the build was broken, then learned that App Router defaults to static prerendering and any use of cookies\(\) requires an actual HTTP request. Adding export const dynamic = 'force-dynamic' told Next.js to render the page per request, so cookies\(\) became valid. The fix works because it makes the rendering mode match the data source.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-07-02T04:41:15.773908+00:00— report_created — created