Target container is not a DOM element ⚛️ React

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

  1. Match the id in index.html and main.jsx
  2. Load the script at the end of body / with defer

Detailed fix by platform

React

  1. ReactDOM.createRoot(document.getElementById('root')).render(<App />);

How to diagnose

  1. Element — Does document.getElementById return null?
  2. 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.