{"record":{"id":"2b595b4565cdda7e","repo":"vercel/next.js","slug":"route-workstore-route-used-apiname-outside-o","errorCode":null,"errorMessage":"Route ${workStore.route} used ${apiName} outside of a Server Component. This is not allowed.","messagePattern":"Route (.+?) used (.+?) outside of a Server Component\\. This is not allowed\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/next/src/server/request/root-params.ts","lineNumber":30,"sourceCode":"import type { ParamValue } from './params'\nimport { actionAsyncStorage } from '../app-render/action-async-storage.external'\nimport { accumulateRootVaryParam } from '../app-render/vary-params'\n\n/**\n * Used for the compiler-generated `next/root-params` module.\n * @internal\n */\nexport function getRootParam(paramName: string): Promise<ParamValue> {\n  const apiName = `\\`import('next/root-params').${paramName}()\\``\n\n  const workStore = workAsyncStorage.getStore()\n  if (!workStore) {\n    throw new InvariantError(`Missing workStore in ${apiName}`)\n  }\n\n  const workUnitStore = workUnitAsyncStorage.getStore()\n  if (!workUnitStore) {\n    throw new Error(\n      `Route ${workStore.route} used ${apiName} outside of a Server Component. This is not allowed.`\n    )\n  }\n\n  const actionStore = actionAsyncStorage.getStore()\n  if (actionStore) {\n    if (actionStore.isAppRoute) {\n      // TODO(root-params): add support for route handlers\n      throw new Error(\n        `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.`\n      )\n    }\n    if (actionStore.isAction && workUnitStore.phase === 'action') {\n      // Actions are not fundamentally tied to a route (even if they're always submitted from some page),\n      // so root params would be inconsistent if an action is called from multiple roots.\n      // Make sure we check if the phase is \"action\" - we should not error in the rerender\n      // after an action revalidates or updates cookies (which will still have `actionStore.isAction === true`)\n      throw new Error(","sourceCodeStart":12,"sourceCodeEnd":48,"githubUrl":"https://github.com/vercel/next.js/blob/0eb377541648e63402a47b38fee00a8d0ce8f8f1/packages/next/src/server/request/root-params.ts#L12-L48","documentation":"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.","triggerScenarios":"A root-params API is called outside a Server Component.","commonSituations":"Importing next/root-params in a Client Component or other unsupported context.","solutions":["Call the next/root-params API only inside Server Components of a route."],"exampleFix":null,"handlingStrategy":"validation","validationCode":null,"typeGuard":null,"tryCatchPattern":null,"preventionTips":[],"tags":[],"backgroundTag":null,"analyzedSha":"0eb377541648e63402a47b38fee00a8d0ce8f8f1","analyzedAt":"2026-08-19T02:10:13.922Z","contentChangedAt":"2026-08-19T02:10:13.922Z","schemaVersion":2},"datasetVersion":"2026-09-14T05:17:10.506Z"}