vercel/next.js · error · Error

Route ${workStore.route} used ${apiName} outside of a Server

Error message

Route ${workStore.route} used ${apiName} outside of a Server Component. This is not allowed.

What it means

Scope detection in getRootParam: no work-unit store was active when the compiler-generated root-params accessor ran, meaning the call happened outside any Server Component render (e.g. from plain module scope or an unsupported context). Root params are tied to a route's render, so a missing scope is rejected.

Source

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

import type { ParamValue } from './params'
import { actionAsyncStorage } from '../app-render/action-async-storage.external'
import { accumulateRootVaryParam } from '../app-render/vary-params'

/**
 * Used for the compiler-generated `next/root-params` module.
 * @internal
 */
export function getRootParam(paramName: string): Promise<ParamValue> {
  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(

View on GitHub (pinned to 0eb3775416)

Solutions

  1. Call the next/root-params API only inside Server Components of a route.
Defensive patterns

Strategy: validation

When it happens

Trigger: A root-params API is called outside a Server Component.

Common situations: Importing next/root-params in a Client Component or other unsupported context.


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