Error: Dynamic server usage: Route couldn't be rendered statically because it used cookies
Error: Dynamic server usage: Route /dashboard couldn't be rendered statically because it used `cookies`.In one sentence: Next.js tried to pre-build a page at build time, but the page reads cookies, headers or search params, which only exist during a real request.
What it means
During `next build`, Next.js renders pages ahead of time when it can. Functions like `cookies()`, `headers()` or reading `searchParams` need a live request, so the page can't be built in advance.
It often appears on Vercel builds after adding login checks to a page that used to be static.
Common causes
- Calling `cookies()` or `headers()` (directly or through a Supabase or auth helper) in a page or layout.
- A fetch with `cache: "no-store"` inside a page Next.js expected to be static.
- Wrapping the call in try/catch, which hides the signal Next.js uses to switch the page to dynamic.
How to fix it
- Mark the page as dynamic: add `export const dynamic = "force-dynamic";` at the top of the page or layout.
- Don't wrap `cookies()` or `headers()` in try/catch that swallows the error.
- If only part of the page needs the user, move that part into its own component and leave the rest static.
Example
export const dynamic = "force-dynamic";
export default async function Dashboard() {
const supabase = await createClient(); // reads cookies
const { data: { user } } = await supabase.auth.getUser();
return <h1>Hi {user?.email}</h1>;
}Tried this and it's still broken? Paste your exact error for a free explanation of your specific case.
Prompt to paste into your AI tool
My Next.js build fails with 'Dynamic server usage ... used cookies'. Find the page or layout in the error, add export const dynamic = 'force-dynamic' there, and remove any try/catch that swallows cookies() or headers() errors. Don't change unrelated code.Still stuck?
Paste your exact error and code. Get a plain-English explanation free, or the full fix for $5.
Hitting errors every day? Builder is $15/mo for 100 fixes per month. Compare plans
Related errors
- Module not found: Can't resolve 'fs'
- Next.js: params should be awaited before using its properties
- Error: supabaseUrl is required
- Error: NEXT_REDIRECT
Weekly: the errors breaking vibe-coded apps and how to fix them. Free.
No spam. Unsubscribe anytime.