Next.js · build warning
Dynamic server usage: Route couldn't be rendered statically because it used cookies
verified on · Next.js 16.4.5 · React 19.3
Check yours: npm ls next react · On a different version? Paste your package.json into the free Doctor and it checks your versions against these fixes.
Error: Dynamic server usage: Route /account couldn't be rendered statically because it used `cookies`. See more info here: https://nextjs.org/docs/messages/dynamic-server-error
digest: 'DYNAMIC_SERVER_USAGE'What it means
During next build, Next.js tries to prerender every page. When a page calls cookies(), headers(), searchParams or a fetch with cache: "no-store", Next.js throws a special internal error to stop and mark the route as dynamic. If your own try/catch catches it and logs it, you see this scary message in the build log. In our Next.js 16.4.5 test the build still passed, the route was listed as dynamic (ƒ) and cookies worked per request with next start. Nothing is broken yet, but the same catch also swallows notFound() and redirect().
Common causes
- cookies(), headers() or auth() wrapped in a try/catch that logs every error
- A fetch with cache: "no-store" inside try/catch (the log says "because it used revalidate: 0 fetch")
- A helper like getUser() that catches everything and is called from a page or layout
- export const dynamic = "error" on that route. Then it isn't a log line but a failed build: Route /x with `dynamic = "error"` couldn't be rendered statically because it used `headers()`
How to fix it
- Call unstable_rethrow(err) from next/navigation as the first line of the catch. It rethrows only Next.js internal errors, so the route goes dynamic quietly and your real errors still get handled
- Or move the cookies() or headers() call above the try, so only the risky part is wrapped
- Don't add export const dynamic = "force-static" to hide it. In our test headers() then came back empty (user agent was null)
- If the page should be static, stop reading cookies or headers there and move that part into a Client Component or a Route Handler
- If you set export const dynamic = "error" on purpose, either remove the request data from that route or remove the setting
import { cookies } from "next/headers";
import { unstable_rethrow } from "next/navigation";
export default async function Page() {
let theme = "light";
try {
const jar = await cookies();
theme = jar.get("theme")?.value ?? theme;
} catch (err) {
unstable_rethrow(err); // Next.js errors
console.error(err);
}
return <p>{theme}</p>;
}Prompt for Cursor or Claude Code
next build logs "Dynamic server usage: Route ... couldn't be rendered statically because it used cookies" (or headers, or a no-store fetch). Find every try/catch in pages, layouts and the helpers they call that wraps cookies(), headers(), auth(), searchParams or a no-store fetch. Add unstable_rethrow(err) from next/navigation as the first line of each catch, or move the request API call above the try. Don't add export const dynamic = "force-static" or remove the error logging. List each file you change.Not quite your error? Paste yours into the free VibeBoot Doctor or browse the Next.js error fixer.
Check your whole repo from the terminal: npx github:vibeboot/vibeboot-doctor (free, offline).
Upgrading from Next.js 15? The Next.js 16 upgrade checklist covers every breaking change, the error it causes and the fix.
next: skip the next one
Skip the setup. The VibeBoot SaaS Starter gives you auth, Stripe and a database already wired on Next.js 16, with AGENTS.md and .cursor/rules that keep your agent on the Next.js 16 conventions. $49, one-time.
14-day money-back guarantee · lifetime updates
Other Next.js errors
- useState / useEffect in a Server Component
- Event handlers cannot be passed to Client Component props
- Functions cannot be passed directly to Client Components
- Only plain objects can be passed to Client Components
- "use client" must be placed before other expressions
- export "metadata" from a "use client" page
$ fixed it? get the next one first
New fixes for what AI agents break, by email.
When we add a fix or a Cursor rule for a new Next.js, Auth.js, Prisma or Stripe break, it goes out in the VibeBoot newsletter. Free, occasional, unsubscribe in one click.