Error: createRoot(...): Target container is not a DOM element.
The element passed to createRoot/render doesn’t exist when the script runs.
Seen on:
React
Meaning
The id in index.html differs from the one in main.jsx, or the script runs before the element is parsed.
Common causes
- id mismatch ("root" vs "app")
- Script in <head> without defer/type="module"
- HTML template not containing the element
⚡ Quick fix
- Match the id in index.html and main.jsx
- Load the script at the end of body / with defer
Detailed fix by platform
React
ReactDOM.createRoot(document.getElementById('root')).render(<App />);
How to diagnose
- Element — Does document.getElementById return null?
- HTML — Correct id?
🧠 Still stuck? Analyze your error
Paste the full message, response headers or stack trace — we'll detect the platform and point to the most likely cause.
Was this page helpful?
Report a correction or suggest an improvement
Last updated 2 Oct 2026