Minified React error #200 in a production build
Uncaught Error: Minified React error #200Short 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.
Fix it fast
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)2Match what you see, then jump to its fix
- 1
console.log prints null.The id in JavaScript does not match the id in the HTMLFix - 2
The 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
console.log prints a real element, or the call is createRoot(<App />).A JSX element is passed instead of the DOM nodeFix
- 1
What does the error look like?
Uncaught Error: Minified React error #200Target 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/null2Fix
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 distConfirmed by react.dev
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.html2Fix
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 buildConfirmed by react.dev
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(" src2Fix
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 buildConfirmed by react.dev
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:
- TaxiDexMy own multi-tenant taxi dispatch SaaS: API, dispatcher portal, driver and passenger apps, and the servers underneath.
- QistLockA NestJS and React SaaS driving an Android Device Owner agent that locks financed phones when payments lapse.
- WorkforceA field app, an admin console and a self-hosted Node.js server for push and reconciliation.
Related fixes
Web apps
React shows Attempted import error when importing a component or function
Attempted import error:
The build found the file but not the name you asked for.
2 causes, each with a fixWeb apps
AxiosError Network Error with code ERR_NETWORK in a React app
Network Error
ERR_NETWORK means the request produced no readable response.
4 causes, each with a fixWeb apps
Axios get works with a URL string but ignores the object passed as the second argument
The server log shows a GET with no query string
axios.get takes a URL and an optional config object.
3 causes, each with a fixWeb apps
Can't resolve '../axios' in a React project
Module not found: Error: Can't resolve '../axios'
A path that starts with ./ or ../ is a file path, not the axios package.
3 causes, each with a fixWeb apps
Axios returns 401 from a React app but the login works elsewhere
Error: Request failed with status code 401
A 401 means the server received the request without valid credentials.
3 causes, each with a fixWeb apps
An axios call never finishes when the API server stops answering
code: 'ECONNABORTED'
Axios has no timeout unless you give it one: the default is 0, which means wait forever.
3 causes, each with a fix