Dynamic server usage: Route couldn't be rendered statically because it used `cookies`
Last verified:
The fix
Dynamic server usage: Route couldn't be rendered statically because it used `cookies`. Await cookies() on the same call stack, outside setTimeout, and do not swallow that throw. The route can then render per request.
- 1
Await cookies() before any timer
Read the cookie on the render's call stack. Pass the value into a timer if you still need one. Do this for
headers()the same way.import { cookies } from "next/headers"; async function readSession() { const cookieStore = await cookies(); return cookieStore.get("session")?.value ?? null; } export default async function Page() { const session = await readSession(); return <p>{session ? "Signed in" : "Signed out"}</p>; } - 2
Stop catching Next.js's own signal
A
try/catcharoundcookies()turns the bailout into this build error. Callunstable_rethrowfromnext/navigationbefore your own handler, soDYNAMIC_SERVER_USAGE,redirect(), andnotFound()keep propagating. A Supabase server client that catches every error fromcookies()needs the same rethrow. - 3
Leave cookies() out of the root layout
A session read in
app/layout.tsxmakes every route dynamic, including the marketing page. Read the cookie in the segment that renders the account UI. - 4
Match the rendering mode you actually want
A dashboard may stay dynamic. A public page should drop the
cookies()call. A static export cannot call it at all. If Cache Components is on, wrap the component that awaitscookies()in<Suspense>and do not addexport const dynamic.force-statichides the error by prerendering an empty cookie store.
Why it happens
While Next.js prerenders a route it throws DynamicServerError from cookies(), headers(), or an uncached fetch, then catches that throw to mark the route dynamic. The build prints Dynamic server usage: Route … couldn't be rendered statically because it used cookies when something else catches the throw first, or when cookies() runs outside the call stack the request was bound to. The docs name setTimeout, setInterval, and a promise that calls cookies() without being awaited.
A page that awaits cookies() in the component body is dynamic on purpose. That is not a failed build. export const dynamic = "error" asks the route to stay static, so the same call fails and the message names that setting. output: 'export' has no server on the request. With Cache Components the sentence changes: the build says it hit uncached or runtime data during prerendering, and the read belongs inside <Suspense>. If that build tells you to remove the dynamic export, remove it. export const dynamic = "force-static" prerenders the route and cookies() does not see the visitor. The page builds, and everyone looks logged out.
The next error you'll probably hit
Once this is fixed, the usual follow-up is cookies() should be awaited before using its value. cookies(), headers(), and draftMode() return a Promise. Next.js 15 warned on the old sync call. Next.js 16 throws.
Prompt to paste back into your AI tool
Paste this above the error.
Next.js failed the build with: Dynamic server usage: Route <path> couldn't be rendered statically because it used `cookies`. The file is <file>. Cache Components are <on or off>. output is <default or export>. Do not add export const dynamic = "force-static". Do not wrap cookies() in try/catch unless you call unstable_rethrow first. Do not call cookies() inside setTimeout or after an un-awaited promise. Do not add force-dynamic on a page that should be static. 1. Await cookies() in the component or helper, on the same call stack, and pass the value onward. 2. If a try/catch swallows the throw, rethrow with unstable_rethrow from next/navigation. 3. If this is the root layout, move the read into the route that needs the session. 4. If cacheComponents is on, wrap that read in Suspense and remove a dynamic export the build rejected. If output is export, delete the cookies() call. Show only that diff.
Common questions
+The page awaits cookies() and the dev server is fine. Why does the build say Dynamic server usage?
Dev does not prerender the route the way the build does. The build throws DynamicServerError and expects to catch it. A try/catch, a setTimeout, or an un-awaited promise takes that throw away from Next.js, and the build prints Dynamic server usage: Route couldn't be rendered statically because it used cookies.
+Will export const dynamic = "force-dynamic" fix it?
It marks a route that is supposed to depend on the request. It does not fix cookies() inside setTimeout, and a Cache Components build tells you to remove the dynamic export. A public page should drop the cookie read instead.
+I set force-static and the error went away, but everyone is logged out. Why?
force-static prerenders one HTML file and cookies() does not see the request. The build is quiet because the session is empty for every visitor. Remove force-static and await cookies() in the route that needs the session.
+The build says uncached or runtime data during prerendering, not Dynamic server usage. Same fix?
That sentence is the Cache Components form. Wrap the component that reads cookies(), headers(), or an uncached fetch in Suspense so the rest of the page can prerender. Do not add export const dynamic when that build tells you to remove it.
Related errors
- cookies() should be awaited before using its valuecookies(), headers(), and draftMode() return a Promise. Next.js 15 warned on the old sync call. Next.js 16 throws.Cursorv0BoltNext.jsSupabaseOct 23, 2026
- useSearchParams() should be wrapped in a suspense boundaryThe production build prerendered a page that reads the query string with useSearchParams() and has no Suspense boundary above that call.Cursorv0BoltNext.jsReactOct 23, 2026
- params is a Promise and must be unwrappedparams is a Promise and must be unwrapped in Next.js 16. await params before use. Do not cast it, and do not add use client just to read it in sync.Cursorv0BoltNext.jsReactOct 20, 2026
- FUNCTION_INVOCATION_TIMEOUTFUNCTION_INVOCATION_TIMEOUT. Log: Vercel Runtime Timeout Error: Task timed out after N seconds. Return sooner, or set maxDuration within the plan.Cursorv0BoltVercelNext.jsNov 4, 2026