Fix Next.js 'Dynamic server usage: Page couldn't be rendered statically'
Understand static vs dynamic rendering when accessing headers(), cookies(), or searchParams.
Error: Dynamic server usage: Page couldn't be rendered statically because it used `cookies` or `headers`
// Add route segment config at the top of your page.tsx:
export const dynamic = "force-dynamic";
export const revalidate = 0; // Disable cache for fresh per-request data
// Or if reading searchParams in Next.js 15+:
export default async function Page({
searchParams,
}: {
searchParams: Promise<{ [key: string]: string | string[] | undefined }>
}) {
const params = await searchParams;
return <div>Search: {params.q}</div>;
}Root Cause & Mechanism Analysis
Why does this error occur?
A page intended for static generation (`output: export` or static generation phase) attempted to call dynamic runtime functions (`cookies()`, `headers()`, or unwrapped `searchParams`).
Frequently Asked Questions
Why did Next.js 15 make headers() and cookies() asynchronous?
Related Developer Error Solutions
Browse All 35 GuidesNext.js Hydration Failed
Resolve Next.js React hydration mismatch errors caused by browser-only APIs (window, localStorage), timestamps, or invalid HTML nesting.
React: Too many re-renders
Prevent infinite re-render loops caused by immediately invoking setState functions inside JSX render bodies.
CORS 'Access-Control-Allow-Origin' Missing
Resolve browser cross-origin resource sharing errors by configuring backend HTTP headers and handling preflight OPTIONS requests.