Fix guides · v0, Cursor, Claude Code, Bolt ·

Fix Next.js "Dynamic server usage" (couldn't be rendered statically)

Error: Dynamic server usage: Route /dashboard couldn't be rendered statically because it used `cookies`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error

"Dynamic server usage" means Next.js tried to pre-render a page at build time, but the page reads something that only exists per request, like cookies(), headers() or searchParams. Normally Next.js catches this quietly and renders the page on request instead. You see the error when your code swallows that signal in a try/catch, reads cookies outside the request (setTimeout or an unawaited promise), or forces the route to be static.

Free · 3 a day · no signup

Common causes – and how to tell which one you have

1. A try/catch catches Next.js's internal signal

How to tell: The build log prints the error but often still succeeds, and the page calls cookies(), headers() or a data function that does, inside a try { ... } catch (e) { console.error(e) } block.

Fix: Call cookies()/headers() outside the try block, or rethrow Next.js errors at the start of the catch with unstable_rethrow(e) from next/navigation.

2. The route is forced to be static

How to tell: The file or a parent layout has export const dynamic = 'force-static' or 'error', or next.config uses output: 'export', while the page reads cookies or headers.

Fix: Remove the forced setting for that route or add export const dynamic = 'force-dynamic' to it. With output: 'export' there is no server, so read cookies on the client or drop the static export.

3. cookies() or headers() is called outside the request

How to tell: The call sits inside setTimeout, setInterval, a callback, or after a promise that isn't awaited. The Next.js docs describe this as losing the async context.

Fix: Call and await cookies()/headers() directly in the page, layout, route handler or server action, and pass the values on as arguments.

4. A shared helper reads auth cookies on every page

How to tell: A Supabase or auth helper (createServerClient, getSession) is called in the root layout, so every page — including ones you expected to be static — becomes dynamic or throws.

Fix: Call the auth helper only in the routes that need the user, or accept that those routes are dynamic and mark them with export const dynamic = 'force-dynamic'.

How to fix it

  1. Read the route in the error (for example /dashboard) and what it used (cookies, headers, searchParams).
  2. Open that route's page.tsx and its layouts, and search for cookies(, headers(, and helpers that call them.
  3. Check whether the call sits inside try/catch. If yes, move it out or add unstable_rethrow(e) as the first line of the catch.
  4. Search for export const dynamic, revalidate and output: 'export' in the route and next.config, and remove settings that force the route static.
  5. If the page should be per-user anyway, add export const dynamic = 'force-dynamic' to that route.
  6. Run next build again and check the route table: the route should show as dynamic (ƒ) without the error.

Using Lovable, Bolt or v0?

In v0 or Bolt, paste the full build error and say: "This route reads cookies or headers. Don't swallow the error in try/catch; make the route dynamic with export const dynamic = 'force-dynamic' if it shows per-user data, and keep auth helpers out of the root layout."

Using Cursor, Claude Code or Windsurf?

Ask Cursor or Claude Code to run next build, then trace the route from the error through its layouts and helpers to every cookies()/headers() call. Have it check for try/catch blocks around those calls, forced static settings, and calls inside callbacks. Confirm the route shows as dynamic in the build output afterwards.

The “fix” to avoid

Agents often wrap the code in more try/catch blocks or add 'use client' to the whole page to make the error disappear. The first hides the real problem; the second breaks server-side auth and data fetching. Let Next.js mark the route dynamic instead.

Copy-paste fix prompt for your AI coding tool

Paste this into Cursor, Claude Code, Lovable or Bolt:

My Next.js build logs "Dynamic server usage: Route ... couldn't be rendered statically because it used cookies/headers". Find that route and every layout and helper it uses that calls cookies(), headers() or reads searchParams. Check: 1) is the call inside a try/catch that swallows Next.js's error? Move it out or add unstable_rethrow(e) at the top of the catch; 2) is the route forced static via export const dynamic = 'force-static'/'error' or output: 'export'? 3) is cookies() called inside setTimeout, a callback or an unawaited promise? Fix the real cause. If the page is per-user, mark it export const dynamic = 'force-dynamic'. Run next build and show me the route table.
Your error looks a bit different? Paste your exact error and get a diagnosis tailored to your code — free.

Questions people ask

Does this error break my site?

Sometimes not: often the build succeeds and the page just renders on each request. But it can also mean a page you wanted to be static isn't, or that a try/catch is hiding real errors. Fix it so the build log stays clean.

Is it bad to use force-dynamic?

No, for pages that show per-user data (dashboards, account pages) rendering on request is correct. Just don't put it on pages that could be static, like a blog.

Why did this start after adding Supabase auth?

Server-side Supabase clients read cookies. If you create one in a layout or a shared helper, every page below it reads cookies and can no longer be static.

Official documentation

Related errors

Get fixes like this every week