{"record":{"id":"0df95418b076074b","repo":"facebook/react","slug":"299-0df954","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/shared/ReactDOM.js","lineNumber":63,"sourceCode":"    console.error(\n      'React depends on Map and Set built-in types. Make sure that you load a ' +\n        'polyfill in older browsers. https://reactjs.org/link/react-polyfills',\n    );\n  }\n}\n\nfunction batchedUpdates<A, R>(fn: (a: A) => R, a: A): R {\n  // batchedUpdates is now just a passthrough noop\n  return fn(a);\n}\n\nfunction createPortal(\n  children: ReactNodeList,\n  container: Element | DocumentFragment,\n  key: ?string = null,\n): React$Portal {\n  if (!isValidContainer(container)) {\n    throw new Error('Target container is not a DOM element.');\n  }\n\n  // TODO: pass ReactDOM portal implementation as third argument\n  // $FlowFixMe[incompatible-type] The Flow type is opaque but there's no way to actually create it.\n  return createPortalImpl(children, container, null, key);\n}\n\nexport {\n  ReactVersion as version,\n  browser,\n  createPortal,\n  flushSync,\n  batchedUpdates as unstable_batchedUpdates,\n  prefetchDNS,\n  preconnect,\n  preload,\n  preloadModule,\n  preinit,","sourceCodeStart":45,"sourceCodeEnd":81,"githubUrl":"https://github.com/facebook/react/blob/eafeac097ba51e1eab809c07102126bd5f8e5425/packages/react-dom/src/shared/ReactDOM.js#L45-L81","documentation":"The top-level react-dom entry re-exports createPortal with the same isValidContainer validation as the client build (nodeType ELEMENT, DOCUMENT, or DOCUMENT_FRAGMENT), throwing error 299 for null or non-DOM containers. A distinct trap for this entry point: importing createPortal from 'react-dom' in non-DOM environments like React Native fails here because no real DOM nodes exist at all.","triggerScenarios":"import {createPortal} from 'react-dom' with a container that is null (failed getElementById), a selector string, a wrapped node, or — in React Native — any host component, since those are not DOM elements.","commonSituations":"Shared code that renders portals imported by both web and React Native builds; missing portal host divs in templates; containers looked up before they exist.","solutions":["Null-check the container before creating the portal","Prefer the createPortal re-export from 'react-dom/client' for web apps","On React Native, use a modal/portal library built for native instead of react-dom's createPortal","Ensure the host element is present before the render that creates the portal"],"exampleFix":"// before\nimport {createPortal} from 'react-dom';\ncreatePortal(<Menu />, document.getElementById('menu-host'));\n\n// after\nimport {createPortal} from 'react-dom/client';\nconst host = document.getElementById('menu-host');\nif (host) {\n  createPortal(<Menu />, host);\n}","handlingStrategy":"type-guard","validationCode":"const isValidPortalContainer = (node: unknown): boolean =>\n  !!(\n    node &&\n    typeof node === 'object' &&\n    (node.nodeType === 1 || node.nodeType === 9 || node.nodeType === 11)\n  );\n\nconst host = document.getElementById('menu-host');\nif (isValidPortalContainer(host)) {\n  createPortal(<Menu />, host);\n}","typeGuard":"function isValidPortalContainer(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 container lookups before creating portals","Import createPortal from react-dom/client in web apps; keep react-dom's portal export out of shared cross-platform code","Never call react-dom's createPortal in React Native — use a native modal/portal library"],"tags":["react-dom","portals","dom","null-container","react-native"],"backgroundTag":"invalid-dom-container","analyzedSha":"eafeac097ba51e1eab809c07102126bd5f8e5425","analyzedAt":"2026-08-21T22:01:08.818Z","schemaVersion":2},"datasetVersion":"2026-08-21T23:17:16.201Z"}