# Error: createRoot(...): Target container is not a DOM element.

**Code:** `Target container is not a DOM element` · **Category:** React · **Seen on:** React

The element passed to createRoot/render doesn’t exist when the script runs.

## 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?

---
Source: [WhatIsMyError](https://whatismyerror.com/errors/react/createroot-target-container-is-not-a-dom-element)
