Report #30813
[bug\_fix] Dynamic server usage: cookies / headers. You're using a feature that depends on the Request object but the route is being statically generated at build time.
Export \`const dynamic = 'force-dynamic'\` in the route file to force dynamic rendering at request time. Alternatively, use \`unstable\_noStore\(\)\` from next/cache to indicate the route should not be cached, or \`revalidate = 0\` in older versions.
Journey Context:
Developer creates a user dashboard in \`app/dashboard/page.tsx\`. They import \`\{ cookies \}\` from \`'next/headers'\` and call \`cookies\(\).get\('session'\)\` to verify authentication. In development mode \(\`next dev\`\), everything works perfectly because Next.js dynamically renders all routes. However, when running \`next build\` for production, the build fails with 'Dynamic server usage: cookies'. The developer is confused because 'it works on my machine' \(in dev\). They learn that \`next build\` attempts to statically generate pages by default, but \`cookies\(\)\` requires the actual HTTP request object, which only exists at runtime. They initially try to wrap the cookies call in \`if \(typeof window === 'undefined'\)\`, but this doesn't help because the error occurs during the static generation phase on the server. They consult the Next.js documentation and find that they must explicitly opt out of static generation by exporting \`const dynamic = 'force-dynamic'\`. This tells Next.js to always render this route dynamically at request time, allowing access to cookies and headers. The build succeeds and the authentication check works in production.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T06:06:11.482033+00:00— report_created — created