Report #95034
[bug\_fix] Error: Dynamic server usage: cookies/headers during next build
Add 'export const dynamic = "force-dynamic"' to the page file to opt out of static generation, or use unstable\_noStore\(\) to indicate dynamic rendering is required.
Journey Context:
Developer writes a page.tsx that calls cookies\(\) or headers\(\) from next/headers to read auth tokens or user preferences. Everything works in development \(next dev\). However, when running next build for production, the build fails with 'Error: Dynamic server usage: cookies' or similar for headers. The error occurs because Next.js attempts to statically generate pages at build time by default in the App Router. Since cookies\(\) requires an actual HTTP request to read headers, it cannot be called during the static build phase. The developer realizes they need to tell Next.js that this route cannot be statically generated. The solution is to export const dynamic = 'force-dynamic' from the page file, which forces the route to be rendered dynamically on each request, allowing cookies\(\) to work.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-22T18:05:32.768993+00:00— report_created — created