vercel/next.js · error · Error

Route ${workStore.route} used ${apiName} inside `"use cache"

Error message

Route ${workStore.route} used ${apiName} inside `"use cache"` nested within `unstable_cache`. Root params are not available in this context.

What it means

Nested-scope check in getRootParam: the accessor ran inside a "use cache" function that is itself nested within unstable_cache. Even the use-cache scope cannot rescue root params there, because the outer unstable_cache boundary still fixes the captured scope; the combination is explicitly unsupported.

Source

Thrown at packages/next/src/server/request/root-params.ts:62

      // Actions are not fundamentally tied to a route (even if they're always submitted from some page),
      // so root params would be inconsistent if an action is called from multiple roots.
      // Make sure we check if the phase is "action" - we should not error in the rerender
      // after an action revalidates or updates cookies (which will still have `actionStore.isAction === true`)
      throw new Error(
        `${apiName} was used inside a Server Action. This is not supported. Functions from 'next/root-params' can only be called in the context of a route.`
      )
    }
  }

  switch (workUnitStore.type) {
    case 'unstable-cache': {
      throw new Error(
        `Route ${workStore.route} used ${apiName} inside \`unstable_cache\`. This is not supported. Use \`"use cache"\` instead.`
      )
    }
    case 'cache': {
      if (!workUnitStore.rootParams) {
        throw new Error(
          `Route ${workStore.route} used ${apiName} inside \`"use cache"\` nested within \`unstable_cache\`. Root params are not available in this context.`
        )
      }
      workUnitStore.readRootParamNames.add(paramName)
      return Promise.resolve(workUnitStore.rootParams[paramName])
    }
    case 'prerender':
    case 'prerender-legacy': {
      return createPrerenderRootParamPromise(
        paramName,
        workStore,
        workUnitStore,
        apiName
      )
    }
    case 'validation-client':
    case 'prerender-client': {
      throw new InvariantError(

View on GitHub (pinned to 0eb3775416)

Solutions

  1. Do not nest "use cache" inside unstable_cache when reading root params; restructure the caching.
Defensive patterns

Strategy: validation

When it happens

Trigger: A root-params API is used in 'use cache' nested in unstable_cache.

Common situations: Root params unavailable inside a 'use cache' scope nested within unstable_cache.


AI-assisted analysis of vercel/next.js@0eb3775416 (2026-08-19). Data as JSON: /api/errors/25e4a7e4e8588208. Report an issue: GitHub.