{"record":{"id":"7cfa845988f129fe","repo":"facebook/react","slug":"attempted-to-load-a-client-module-outside-the-host","errorCode":null,"errorMessage":"Attempted to load a Client Module outside the hosted root.","messagePattern":"Attempted to load a Client Module outside the hosted root\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-server-dom-esm/src/server/ReactFlightServerConfigESMBundler.js","lineNumber":51,"sourceCode":"} from '../ReactFlightESMReferences';\n\nexport function getClientReferenceKey(\n  reference: ClientReference<any>,\n): ClientReferenceKey {\n  return reference.$$id;\n}\n\nexport function resolveClientReferenceMetadata<T>(\n  config: ClientManifest,\n  clientReference: ClientReference<T>,\n): ClientReferenceMetadata {\n  const baseURL: string = config;\n  const id = clientReference.$$id;\n  const idx = id.lastIndexOf('#');\n  const exportName = id.slice(idx + 1);\n  const fullURL = id.slice(0, idx);\n  if (!fullURL.startsWith(baseURL)) {\n    throw new Error(\n      'Attempted to load a Client Module outside the hosted root.',\n    );\n  }\n  // Relative URL\n  const modulePath = fullURL.slice(baseURL.length);\n  return [modulePath, exportName];\n}\n\nexport function getServerReferenceId<T>(\n  config: ClientManifest,\n  serverReference: ServerReference<T>,\n): ServerReferenceId {\n  return serverReference.$$id;\n}\n\nexport function getServerReferenceBoundArguments<T>(\n  config: ClientManifest,\n  serverReference: ServerReference<T>,","sourceCodeStart":33,"sourceCodeEnd":69,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-server-dom-esm/src/server/ReactFlightServerConfigESMBundler.js#L33-L69","documentation":"Server-side mirror of the client root check. When the Flight serializer encounters a client reference (an import of a 'use client' module), resolveClientReferenceMetadata strips the configured baseURL from the module's $$id to compute the relative module path sent to the client. If $$id does not start with baseURL — the string config passed to the esm server's renderToPipeableStream/renderToReadableStream — the module lies outside the hosted root and serialization aborts.","triggerScenarios":"renderToPipeableStream(<App/>, baseURL) is given a baseURL that does not prefix the ids the bundler assigned to client modules: an https base while ids are file paths, a different workspace root, or a client manifest produced by another build.","commonSituations":"Monorepos where client and server bundles build from different roots; deploying under a new mount path; switching between file-based and URL-based module ids; stale client manifest after restructuring.","solutions":["Pass the exact root the bundler used when it generated client module ids as the render config string","Log clientReference.$$id when it fails and diff it against the configured baseURL to find the mismatch","Rebuild the client bundle/manifest so the ids and the server's baseURL agree"],"exampleFix":"// before — bundler ids are file URLs, server passes an https base\nrenderToPipeableStream(<App/>, 'https://cdn.example.com/app/');\n\n// after — server config matches the ids the bundler emitted\nconst MODULE_BASE = 'file:///workspace/app/'; // same root the client manifest uses\nrenderToPipeableStream(<App/>, MODULE_BASE);","handlingStrategy":"validation","validationCode":"export function assertManifestInRoot(clientIds, baseURL) {\n  const bad = clientIds.filter(id => !id.startsWith(baseURL));\n  if (bad.length > 0) {\n    throw new Error('Client modules outside baseURL ' + baseURL + ': ' + bad.join(', '));\n  }\n}","typeGuard":"export function isClientReferenceInRoot(id, baseURL) {\n  return typeof id === 'string' && id.startsWith(baseURL);\n}","tryCatchPattern":null,"preventionTips":["Derive the server render config and the bundler's id root from the same constant","Validate all manifest ids against the base at build time","Re-verify after changing deployment mount paths or workspace layout"],"tags":["react-server-components","base-url","client-references","bundler"],"backgroundTag":"rsc-base-url-mismatch","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}