Report #59246
[bug\_fix] Server Component dynamic rendering error when using headers/cookies
Add \`export const dynamic = 'force-dynamic'\` to the page/layout file, or use \`unstable\_noStore\(\)\` from next/cache to opt the route out of static generation.
Journey Context:
Developer creates a Server Component in the App Router that imports \{ cookies \} from 'next/headers' to read a session token. Works in development \(next dev\). Runs next build for production and encounters an error: 'Dynamic server usage: cookies' or 'Page with dynamic = "error" encountered dynamic data method'. Developer confused because cookies\(\) is designed for Server Components. Learns that Next.js App Router defaults to static rendering \(Static Site Generation\) at build time, meaning request-specific APIs like cookies\(\) or headers\(\) are unavailable because there's no request at build time. Realizes the entire route must be marked as dynamic. Discovers they can add \`export const dynamic = 'force-dynamic'\` \(or 'auto'\) to the page file, or use the \`unstable\_noStore\(\)\` import to indicate this component should not be cached or statically generated. Applies fix, build succeeds, and the route renders dynamically per-request.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-20T05:56:14.674331+00:00— report_created — created