vercel/next.js · error · Error

Route ${workStore.route} used `cookies()` inside `generateSt

Error message

Route ${workStore.route} used `cookies()` inside `generateStaticParams`. This is not supported because `generateStaticParams` runs at build time without an HTTP request. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context

What it means

Error "Route ${workStore.route} used `cookies()` inside `generateStaticParams`. This is not supported because `generateStaticParams` runs at build time without an HTTP request. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context" thrown in vercel/next.js.

Source

Thrown at packages/next/src/server/request/cookies.ts:72

    if (workStore.dynamicShouldError) {
      throw new StaticGenBailoutError(
        `Route ${workStore.route} with \`dynamic = "error"\` couldn't be rendered statically because it used \`cookies()\`. See more info here: https://nextjs.org/docs/app/building-your-application/rendering/static-and-dynamic#dynamic-rendering`
      )
    }

    if (workUnitStore) {
      switch (workUnitStore.type) {
        case 'cache':
          const error = createCookiesInUseCacheError(workStore.route)
          Error.captureStackTrace(error, cookies)
          applyOwnerStack(error)
          workStore.invalidDynamicUsageError ??= error
          throw error
        case 'unstable-cache':
          throw createCookiesInUnstableCacheError(workStore.route)
        case 'generate-static-params':
          throw new Error(
            `Route ${workStore.route} used \`cookies()\` inside \`generateStaticParams\`. This is not supported because \`generateStaticParams\` runs at build time without an HTTP request. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context`
          )
        case 'prerender':
          return makeHangingCookies(workStore, workUnitStore)
        case 'prerender-client':
        case 'validation-client':
          const exportName = '`cookies`'
          throw new InvariantError(
            `${exportName} must not be used within a Client Component. Next.js should be preventing ${exportName} from being included in Client Components statically, but did not in this case.`
          )
        case 'prerender-legacy':
          // We track dynamic access here so we don't need to wrap the cookies
          // in individual property access tracking.
          return throwToInterruptStaticGeneration(
            callingExpression,
            workStore,
            workUnitStore
          )

View on GitHub (pinned to 258b1c1bc0)

Solutions

  1. Do not call cookies() inside generateStaticParams; use params passed to it instead.
Defensive patterns

Strategy: try-catch

When it happens

Trigger: cookies() is called inside generateStaticParams.

Common situations: Using cookies at build time inside generateStaticParams where no request exists.


AI-assisted analysis of vercel/next.js@258b1c1bc0 (2026-09-01). Data as JSON: /api/errors/c2c35e6c4b061a11. Report an issue: GitHub.