{"record":{"id":"5352dd91d0548a77","repo":"facebook/react","slug":"299-5352dd","errorCode":"299","errorMessage":"Target container is not a DOM element.","messagePattern":"Target container is not a DOM element\\.","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"packages/react-dom/src/client/ReactDOMRoot.js","lineNumber":176,"sourceCode":"          console.error(\n            'Attempted to synchronously unmount a root while React was already ' +\n              'rendering. React cannot finish unmounting the root until the ' +\n              'current render has completed, which may lead to a race condition.',\n          );\n        }\n      }\n      updateContainerSync(null, root, null, null);\n      flushSyncWork();\n      unmarkContainerAsRoot(container);\n    }\n  };\n\nexport function createRoot(\n  container: Element | Document | DocumentFragment,\n  options?: CreateRootOptions,\n): RootType {\n  if (!isValidContainer(container)) {\n    throw new Error('Target container is not a DOM element.');\n  }\n\n  warnIfReactDOMContainerInDEV(container);\n\n  const concurrentUpdatesByDefaultOverride = false;\n  let isStrictMode = false;\n  let identifierPrefix = '';\n  let onUncaughtError = defaultOnUncaughtError;\n  let onCaughtError = defaultOnCaughtError;\n  let onRecoverableError = defaultOnRecoverableError;\n  let onDefaultTransitionIndicator = defaultOnDefaultTransitionIndicator;\n  let transitionCallbacks = null;\n\n  // $FlowFixMe[invalid-compare]\n  if (options !== null && options !== undefined) {\n    if (__DEV__) {\n      if ((options as any).hydrate) {\n        console.warn(","sourceCodeStart":158,"sourceCodeEnd":194,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-dom/src/client/ReactDOMRoot.js#L158-L194","documentation":"createRoot checks its first argument with isValidContainer (Element, Document, or DocumentFragment nodeType) before creating a FiberRoot, and throws error 299 otherwise. The overwhelmingly common input that fails is null, returned by document.getElementById when the element is missing.","triggerScenarios":"createRoot(document.getElementById('root')) when the script runs before the DOM is parsed, the id is misspelled or case-mismatched, or the HTML template omits the root element; also passing a component instance or props object by mistake.","commonSituations":"Script loaded synchronously in <head> without defer; static HTML missing <div id=\"root\">; ids renamed in the template but not in the entry file; SSR shells that do not emit the mount point.","solutions":["Move the script to the end of <body> or add defer/type=\"module\" so the DOM exists first","Confirm the id matches exactly (case-sensitive) in the served HTML and the entry file","Null-check the container and fail fast with a clear message naming the missing selector","If mounting must happen before parse, wrap in DOMContentLoaded"],"exampleFix":"// before (in <head>, element not parsed yet)\nconst root = createRoot(document.getElementById('root'));\n\n// after (deferred entry)\nconst el = document.getElementById('root');\nif (!el) throw new Error('#root not found — check the HTML template');\nconst root = createRoot(el);","handlingStrategy":"type-guard","validationCode":"function isValidReactContainer(node: unknown): boolean {\n  return !!(\n    node &&\n    typeof node === 'object' &&\n    (node.nodeType === 1 || node.nodeType === 9 || node.nodeType === 11)\n  );\n}\n\nconst el = document.getElementById('root');\nif (!isValidReactContainer(el)) {\n  throw new Error('#root not found in the document — check the HTML template and script loading order');\n}\nconst root = createRoot(el);","typeGuard":"function isValidReactContainer(node: unknown): node is Element | Document | DocumentFragment {\n  return !!(\n    node &&\n    typeof node === 'object' &&\n    (node.nodeType === 1 || node.nodeType === 9 || node.nodeType === 11)\n  );\n}","tryCatchPattern":null,"preventionTips":["Load the entry script with defer, type=\"module\", or at the end of <body>","Assert the mount element exists on boot with a descriptive error naming the selector","Keep mount-point ids in one shared constant used by both template and entry code"],"tags":["react-dom","createroot","bootstrap","dom","null-container"],"backgroundTag":"invalid-dom-container","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-22T04:17:13.399Z"}