{"record":{"id":"09306f81fd5c12fb","repo":"facebook/react","slug":"299-09306f","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/ReactDOMRootFB.js","lineNumber":411,"sourceCode":"  if (disableLegacyMode) {\n    if (__DEV__) {\n      console.error(\n        'ReactDOM.render was removed in React 19. Use createRoot instead.',\n      );\n    }\n    throw new Error('ReactDOM: Unsupported Legacy Mode API.');\n  }\n  if (__DEV__) {\n    console.error(\n      'ReactDOM.render has not been supported since React 18. Use createRoot ' +\n        'instead. Until you switch to the new API, your app will behave as ' +\n        \"if it's running React 17. Learn \" +\n        'more: https://react.dev/link/switch-to-createroot',\n    );\n  }\n\n  if (!isValidContainer(container)) {\n    throw new Error('Target container is not a DOM element.');\n  }\n\n  if (__DEV__) {\n    const isModernRoot =\n      isContainerMarkedAsRoot(container) &&\n      container._reactRootContainer === undefined;\n    if (isModernRoot) {\n      console.error(\n        'You are calling ReactDOM.render() on a container that was previously ' +\n          'passed to ReactDOMClient.createRoot(). This is not supported. ' +\n          'Did you mean to call root.render(element)?',\n      );\n    }\n  }\n  return legacyRenderSubtreeIntoContainer(\n    null,\n    // $FlowFixMe[incompatible-type]\n    element,","sourceCodeStart":393,"sourceCodeEnd":429,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-dom/src/client/ReactDOMRootFB.js#L393-L429","documentation":"In the legacy ReactDOM.render path, the container is validated with isValidContainer (Element/Document/DocumentFragment nodeTypes) and throws error 299 when it is null or not a DOM node. In React 19 builds this line is unreachable because the disableLegacyMode throw (code 509) fires first; error 299 on this path indicates a build with legacy mode still enabled (React 18-style) receiving a bad container.","triggerScenarios":"ReactDOM.render(<App />, container) on a legacy-mode build where container is null (failed getElementById), a selector string, or another non-DOM value.","commonSituations":"React 18 codebases calling render before the DOM is ready; typo'd root ids; templates missing the mount div while legacy API is still in use.","solutions":["Null-check the container before calling ReactDOM.render and fix the selector/id","Ensure the script runs after the DOM parses (defer, end of body)","Migrate to createRoot(container).render(...), which reports the same problem with the modern API"],"exampleFix":"// before\nReactDOM.render(<App />, document.getElementById('root'));\n\n// after\nconst el = document.getElementById('root');\nif (el) {\n  ReactDOM.render(<App />, el);\n}","handlingStrategy":"type-guard","validationCode":"const el = document.getElementById('root');\nconst isValid = !!(\n  el &&\n  typeof el === 'object' &&\n  (el.nodeType === 1 || el.nodeType === 9 || el.nodeType === 11)\n);\nif (isValid) {\n  ReactDOM.render(<App />, el);\n} else {\n  throw new Error('Root container missing — check the mount element before render');\n}","typeGuard":"function isValidLegacyContainer(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":["Null-check getElementById before every legacy render call","Verify the script runs after DOM parsing (defer or end of body)","Migrate to createRoot, which surfaces the same problem with the supported API"],"tags":["react-dom","legacy-api","dom","null-container"],"backgroundTag":"invalid-dom-container","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}