vercel/next.js · error · Error

`cacheLife()` can only be called during App Router rendering

Error message

`cacheLife()` can only be called during App Router rendering at the moment.

What it means

Guard in cacheLife(): the profile argument was a string, but workAsyncStorage.getStore() returned no work store — the call is happening outside an App Router render request (no active request AsyncLocalStorage context, e.g. at module scope or in a plain Node context). Without the store the profile cannot be resolved against the route's configured cacheLife profiles, so the sentinel error fires.

Source

Thrown at packages/next/src/server/use-cache/cache-life.ts:59

    case 'prerender-legacy':
    case 'request':
    case 'unstable-cache':
    case 'generate-static-params':
    case undefined:
      throw createCacheLifeOutsideUseCacheError(
        workAsyncStorage.getStore()?.route
      )
    case 'cache':
    case 'private-cache':
      break
    default:
      workUnitStore satisfies never
  }

  if (typeof profile === 'string') {
    const workStore = workAsyncStorage.getStore()
    if (!workStore) {
      throw new Error(
        '`cacheLife()` can only be called during App Router rendering at the moment.'
      )
    }

    // TODO: This should be globally available and not require an AsyncLocalStorage.
    const configuredProfile = workStore.cacheLifeProfiles[profile]
    if (configuredProfile === undefined) {
      if (workStore.cacheLifeProfiles[profile.trim()]) {
        throw new Error(
          `Unknown \`cacheLife()\` profile "${profile}" is not configured in next.config.js\n` +
            `Did you mean "${profile.trim()}" without the spaces?`
        )
      }
      throw new Error(
        `Unknown \`cacheLife()\` profile "${profile}" is not configured in next.config.js\n` +
          'module.exports = {\n' +
          '  cacheLife: {\n' +
          `    "${profile}": ...\n` +

View on GitHub (pinned to 258b1c1bc0)

Solutions

  1. Call cacheLife() only inside App Router rendering (a page/layout with "use cache").
Defensive patterns

Strategy: type-guard

When it happens

Trigger: cacheLife() is called outside App Router rendering.

Common situations: Calling cacheLife() in a context without an active work unit, such as a route handler or action.


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