Maaz Zindani

Loading the index…

↑↓ move↵ openesc close4072 pages
Next.js and React

Minified React error #200 in a production build

ErrorUncaught Error: Minified React error #200

Short answer

Error 200 is React's production code for 'Target container is not a DOM element.' The value passed to createRoot is null or not a DOM node. Usually the id in the JavaScript does not match the HTML, the script runs before the root element exists, or a JSX element was passed instead of a node.

  • Applies to React 18, React 19, Vite 7, Node.js 22
  • Updated
  • By Maaz Zindani, Senior Software Engineer

Fix it fast

  1. 1Find out which cause you have

    Log what getElementById returns right before createRoot. The result tells you which cause applies: null, or something that is not an element.

    const domNode = document.getElementById('root')
    console.log(domNode)
    const root = createRoot(domNode)
  2. 2Match what you see, then jump to its fix

    1. 1console.log prints null.The id in JavaScript does not match the id in the HTMLFix
    2. 2The id matches, yet the log prints null; the script tag comes before the div in the HTML.The script runs before the root element existsFix
    3. 3console.log prints a real element, or the call is createRoot(<App />).A JSX element is passed instead of the DOM nodeFix

What does the error look like?

  • Uncaught Error: Minified React error #200
  • Target container is not a DOM element.

Cause 1 of 3

The id in JavaScript does not match the id in the HTML

1Check

Compare the string in getElementById with the id attribute of the container in index.html. A typo, a different case or a renamed container is enough.

grep -n "getElementById" src/main.* src/index.*
grep -n "id=" index.html public/index.html 2>/dev/null

2Fix

Make the two match exactly.

<!-- index.html -->
<div id="root"></div>

3Verify

Reload the page; the log now prints the div element.

npm run build && npx serve dist

Confirmed by react.dev

Did this fix it?

Cause 2 of 3

The script runs before the root element exists

1Check

A script cannot see DOM nodes that appear after it in the HTML. Open the built page and see where the bundle's script tag sits relative to the container.

grep -n "<script\|id=\"root\"" index.html

2Fix

Move the script tag below the container, or add defer so it runs after the document is parsed.

<div id="root"></div>
<script src="bundle.js" defer></script>

3Verify

Reload and confirm the page renders.

npm run build

Confirmed by react.dev

Did this fix it?

Cause 3 of 3

A JSX element is passed instead of the DOM node

1Check

Look at the argument of createRoot. The docs name passing the component as a common mistake: createRoot takes a node, and render takes the element.

grep -rn "createRoot(" src

2Fix

Pass the DOM node to createRoot and the JSX to render.

const root = createRoot(document.getElementById('root'))
root.render(<App />)

3Verify

Rebuild and load the page without the error.

npm run build

Confirmed by react.dev

Did this fix it?

How do I stop it coming back?

  • Keep the root id in one place, such as the HTML template, and read it with the same string everywhere.
  • Load app bundles with defer, or put them at the end of the body.
  • Run the development build when you hit a minified error: it prints the full message instead of a code.

Sources

How was this page made?

I drafted this page with AI assistance from the official documents listed under Sources. Every cause above names the document that confirms it. I have not reproduced this fix on a machine of my own yet, so read it as documented guidance, not a test report. Found a mistake? Tell me.

Which stack is behind this page?

Projects of mine built on the same technologies:

Related fixes

Next step

Want this handled for good?

I look after servers, apps and releases end to end. Tell me what keeps breaking.