vercel/next.js · error

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

Error message

Route ${workStore.route} used `cookies()` inside `after()` while rendering. This is not supported. If you need this data inside an `after()` callback, use `cookies()` outside of the callback. See more info here: https://nextjs.org/docs/app/api-reference/functions/after

What it means

Error "Route ${workStore.route} used `cookies()` inside `after()` while rendering. This is not supported. If you need this data inside an `after()` callback, use `cookies()` outside of the callback. See more info here: https://nextjs.org/docs/app/api-reference/functions/after" thrown in vercel/next.js.

Source

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

  RENDER_STAGES_BY_DATA_KIND,
} from '../dynamic-rendering-utils'
import { createDedupedByCallsiteServerErrorLoggerDev } from '../create-deduped-by-callsite-server-error-logger'
import { isRequestApiAllowedInCurrentPhase } from './utils'
import { applyOwnerStack } from '../dynamic-rendering-utils'
import { InvariantError } from '../../shared/lib/invariant-error'
import {
  createCookiesInUseCacheError,
  createCookiesInUnstableCacheError,
} from '../use-cache/use-cache-messages'

export function cookies(): Promise<ReadonlyRequestCookies> {
  const callingExpression = 'cookies'
  const workStore = workAsyncStorage.getStore()
  const workUnitStore = workUnitAsyncStorage.getStore()

  if (workStore) {
    if (workUnitStore && !isRequestApiAllowedInCurrentPhase(workUnitStore)) {
      throw new Error(
        `Route ${workStore.route} used \`cookies()\` inside \`after()\` while rendering. This is not supported. If you need this data inside an \`after()\` callback, use \`cookies()\` outside of the callback. See more info here: https://nextjs.org/docs/app/api-reference/functions/after`
      )
    }

    if (workStore.forceStatic) {
      // When using forceStatic we override all other logic and always just return an empty
      // cookies object without tracking
      const underlyingCookies = createEmptyCookies()
      return makeUntrackedCookies(underlyingCookies)
    }

    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) {

View on GitHub (pinned to 258b1c1bc0)

Solutions

  1. Read cookies() before scheduling after(), and pass the values into the callback closure.
Defensive patterns

Strategy: validation

When it happens

Trigger: cookies() is called inside an after() callback during render.

Common situations: Reading cookies inside unstable_after; read them outside and pass values in.


AI-assisted analysis of vercel/next.js@258b1c1bc0 (2026-08-19). Data as JSON: /api/errors/8460b5308e0bf13f. Report an issue: GitHub.