vercel/next.js · error · Error

Route ${workStore.route} used `unstable_prefetch()` inside a

Error message

Route ${workStore.route} used `unstable_prefetch()` inside a function cached with `unstable_cache()`. The `unstable_prefetch()` function is used to indicate the subsequent code must not run in the app shell, but `unstable_cache()` caches must be able to be produced before a prefetch, so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_cache

What it means

Error "Route ${workStore.route} used `unstable_prefetch()` inside a function cached with `unstable_cache()`. The `unstable_prefetch()` function is used to indicate the subsequent code must not run in the app shell, but `unstable_cache()` caches must be able to be produced before a prefetch, so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_cache" thrown in vercel/next.js.

Source

Thrown at packages/next/src/server/request/cache-stages.ts:133

      const error = new Error(
        `Route ${workStore.route} used \`unstable_prefetch()\` inside "use cache". This is not currently supported. Instead, move the "use cache" directive to a function that's called below \`await unstable_prefetch()\`, so that the cached content is deferred to the prefetch without caching the stage boundary itself. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache`
      )
      Error.captureStackTrace(error, unstable_prefetch)
      applyOwnerStack(error)
      workStore.invalidDynamicUsageError ??= error
      throw error
    }
    case 'private-cache': {
      const error = new Error(
        `Route ${workStore.route} used \`unstable_prefetch()\` inside "use cache: private". This is not currently supported. Instead, move the "use cache" directive to a function that's called below \`await unstable_prefetch()\`, so that the cached content is deferred to the prefetch without caching the stage boundary itself. See more info here: https://nextjs.org/docs/messages/next-request-in-use-cache`
      )
      Error.captureStackTrace(error, unstable_prefetch)
      applyOwnerStack(error)
      workStore.invalidDynamicUsageError ??= error
      throw error
    }
    case 'unstable-cache': {
      throw new Error(
        `Route ${workStore.route} used \`unstable_prefetch()\` inside a function cached with \`unstable_cache()\`. The \`unstable_prefetch()\` function is used to indicate the subsequent code must not run in the app shell, but \`unstable_cache()\` caches must be able to be produced before a prefetch, so this function is not allowed in this scope. See more info here: https://nextjs.org/docs/app/api-reference/functions/unstable_cache`
      )
    }
    case 'generate-static-params': {
      throw new Error(
        `Route ${workStore.route} used \`unstable_prefetch()\` inside \`generateStaticParams\`. This is not supported because \`generateStaticParams\` runs at build time without a prefetch. Read more: https://nextjs.org/docs/messages/next-dynamic-api-wrong-context`
      )
    }
    case 'prerender-client':
    case 'validation-client': {
      const exportName = '`unstable_prefetch`'
      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': {
      // NOTE: Should not be reachable, because we don't use this mode in cacheComponents,
      // which we require at the top

View on GitHub (pinned to 258b1c1bc0)

Solutions

  1. Move the 'use cache' directive off the function containing unstable_prefetch() and onto a function called below 'await unstable_prefetch()', so the cached content is deferred without caching the stage boundary
  2. Restructure so the unstable_cache()'d function no longer calls unstable_prefetch()
  3. Remove unstable_prefetch() from the cached function if the prefetch stage is not needed there
Defensive patterns

Strategy: validation

When it happens

Trigger: Thrown at packages/next/src/server/request/cache-stages.ts:121 when the library encounters an invalid state.

Common situations: See trigger scenarios.


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