{"record":{"id":"9432395079f3245e","repo":"vercel/next.js","slug":"route-store-route-with-dynamic-error-coul","errorCode":null,"errorMessage":"Route ${store.route} with `dynamic = \"error\"` couldn't be rendered statically because it used `${expression}`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering","messagePattern":"Route (.+?) with `dynamic = \"error\"` couldn't be rendered statically because it used `(.+?)`\\. See more info here: https://nextjs\\.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering","errorType":"exception","errorClass":"StaticGenBailoutError","httpStatus":null,"severity":"error","filePath":"packages/next/src/server/app-render/dynamic-rendering.ts","lineNumber":205,"sourceCode":"        // A private cache scope is already dynamic by definition.\n        return\n      case 'prerender-legacy':\n      case 'prerender-ppr':\n      case 'request':\n      case 'generate-static-params':\n        break\n      default:\n        workUnitStore satisfies never\n    }\n  }\n\n  // If we're forcing dynamic rendering or we're forcing static rendering, we\n  // don't need to do anything here because the entire page is already dynamic\n  // or it's static and it should not throw or postpone here.\n  if (store.forceDynamic || store.forceStatic) return\n\n  if (store.dynamicShouldError) {\n    throw new StaticGenBailoutError(\n      `Route ${store.route} with \\`dynamic = \"error\"\\` couldn't be rendered statically because it used \\`${expression}\\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`\n    )\n  }\n\n  if (workUnitStore) {\n    switch (workUnitStore.type) {\n      case 'prerender-ppr':\n        return postponeWithTracking(\n          store.route,\n          expression,\n          workUnitStore.dynamicTracking\n        )\n      case 'prerender-legacy':\n        workUnitStore.revalidate = 0\n\n        // We aren't prerendering, but we are generating a static page. We need\n        // to bail out of static generation.\n        const err = new DynamicServerError(","sourceCodeStart":187,"sourceCodeEnd":223,"githubUrl":"https://github.com/vercel/next.js/blob/0ae8c72462952df163f1b1e0726641bc5b40dc93/packages/next/src/server/app-render/dynamic-rendering.ts#L187-L223","documentation":"A StaticGenBailoutError from markCurrentScopeAsDynamic(). When a route is configured with dynamic = 'error' (or dynamicParams = false in some contexts) and the render attempts to use a dynamic API (the `expression`, e.g. cookies(), headers(), searchParams, or reading request data), the framework refuses to render it statically. dynamicShouldError is true, so instead of postponing, it throws this bailout error.","triggerScenarios":"A page/layout sets `export const dynamic = 'error'` (meaning: this route MUST be static, error if it can't be). During prerender/static generation, the component calls a dynamic function (cookies(), headers(), searchParams, or uses request-only data). markCurrentScopeAsDynamic sees store.dynamicShouldError and throws StaticGenBailoutError.","commonSituations":"A developer adds `dynamic = 'error'` to force static rendering but the component reads cookies/headers/searchParams; a shared component unexpectedly calls a dynamic API; upgrading Next.js where stricter dynamic detection now flags a previously-allowed access; mixing dynamic data fetch with a static-only intent.","solutions":["Remove or change `export const dynamic = 'error'` to 'force-static', 'force-dynamic', or omit it to allow the appropriate rendering mode.","Move the dynamic API call (cookies/headers/searchParams) out of the static component into a component rendered dynamically, or into a Client Component.","If the access is unintentional, audit the component (and imported shared components) for cookies()/headers()/searchParams usage and remove it.","Use `export const dynamicParams = false` instead if you only want to restrict dynamic route params, not all dynamic data."],"exampleFix":"// before\n// export const dynamic = 'error'\n// export default function Page({ cookies }) { const c = cookies() ... }\n\n// after\n// export const dynamic = 'force-dynamic'\n// export default function Page() { const c = cookies() ... }","handlingStrategy":"type-guard","validationCode":"// Static analysis: ensure dynamic APIs aren't used in static routes.\n// At code level, decide rendering mode based on data needs:\nconst needsDynamic = (page) => page.usesCookies || page.usesHeaders\nexport const dynamic = needsDynamic(this) ? 'force-dynamic' : 'error'","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Only set dynamic='error' when you are certain no dynamic API is used.","Audit imported/shared components for cookies()/headers()/searchParams usage.","Prefer dynamicParams=false if you only want to constrain route params.","Run a prerender dry-run to catch dynamic usage before relying on the error."],"tags":["dynamic-rendering","static-generation","route-config","prerender"],"analyzedSha":"0ae8c72462952df163f1b1e0726641bc5b40dc93","analyzedAt":"2026-08-06T19:44:29.143Z","schemaVersion":2},"datasetVersion":"2026-08-07T02:17:10.218Z"}