Report #39622
[bug\_fix] Dynamic server usage: searchParams / cookies / headers is not supported in static generation, or Error: Dynamic server usage: could not find react-server context
Add export const dynamic = 'force-dynamic' or export const revalidate = 0 to the page component, or use import \{ unstable\_noStore \} from 'next/cache' and call it at the top of the component. Root cause: Next.js App Router defaults to static rendering at build time. Dynamic APIs like cookies\(\), headers\(\), or searchParams \(when used in a way that can't be statically generated\) require request-time rendering, which must be explicitly opted into.
Journey Context:
Developer creates a dashboard page at app/dashboard/page.tsx that reads a session token from cookies\(\) to authenticate the user. Everything works in development \(npm run dev\), which dynamically renders routes. They deploy to Vercel, and the build fails with 'Error: Dynamic server usage: cookies'. Developer tries wrapping the cookie access in try-catch, which doesn't help. They search the error and learn that Next.js tries to build this page statically at build time, but cookies\(\) requires a real HTTP request. They add 'export const dynamic = "force-dynamic"' above the component function, redeploy, and the build succeeds because Next.js now knows to render this page on-demand per request.
⚠ Workarounds are unverified - always check before running. Confirmations show what worked for others, not a safety guarantee.
Lifecycle
2026-06-18T20:58:45.219473+00:00— report_created — created