vercel/next.js · error · Error

Route ${workStore.route} used ${apiName} inside a Route Hand

Error message

Route ${workStore.route} used ${apiName} inside a Route Handler. Support for this API in Route Handlers is planned for a future version of Next.js.

What it means

Scope check in getRootParam: the call happened inside a Route Handler (actionStore.isAppRoute). Root params are derived from the route tree during component rendering and are not yet wired into the app-route execution path, so accessing them there is a documented not-yet-supported error rather than a crash.

Source

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

  const apiName = `\`import('next/root-params').${paramName}()\``

  const workStore = workAsyncStorage.getStore()
  if (!workStore) {
    throw new InvariantError(`Missing workStore in ${apiName}`)
  }

  const workUnitStore = workUnitAsyncStorage.getStore()
  if (!workUnitStore) {
    throw new Error(
      `Route ${workStore.route} used ${apiName} outside of a Server Component. This is not allowed.`
    )
  }

  const actionStore = actionAsyncStorage.getStore()
  if (actionStore) {
    if (actionStore.isAppRoute) {
      // TODO(root-params): add support for route handlers
      throw new Error(
        `Route ${workStore.route} used ${apiName} inside a Route Handler. Support for this API in Route Handlers is planned for a future version of Next.js.`
      )
    }
    if (actionStore.isAction && workUnitStore.phase === 'action') {
      // 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.`

View on GitHub (pinned to 0eb3775416)

Solutions

  1. Do not use next/root-params in Route Handlers; read params from the handler context instead.
Defensive patterns

Strategy: validation

When it happens

Trigger: A root-params API is called inside a Route Handler.

Common situations: Using next/root-params inside route.ts, which is not yet supported.


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