Maaz Zindani

Loading the index…

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

Vite cannot find react-dom/client in main.jsx

ErrorFailed to resolve import "react-dom/client" from "src/main.jsx". Does the file exist?

Short answer

react-dom/client exists in React 18 and newer. Vite fails to resolve it when react-dom is not installed in this project, when the installed version is older than 18, or when a stale pre-bundle cache points at old files. Install matching react and react-dom, then restart Vite with --force.

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

Fix it fast

  1. 1Find out which cause you have

    Ask npm which react-dom this project actually has. An empty result or a version below 18 decides the cause.

    npm ls react react-dom
  2. 2Match what you see, then jump to its fix

    1. 1npm ls prints (empty) or a missing line for react-domreact-dom is not installed in this projectFix
    2. 2npm ls shows react or react-dom 17 or olderAn older React is installed, which has no react-dom/clientFix
    3. 3The package is in node_modules and at the right version, yet the error staysDependencies were changed but Vite still uses its old pre-bundleFix

What does the error look like?

  • Failed to resolve import "react-dom/client" from "src/main.jsx". Does the file exist?
  • ReactDOM.render is no longer supported in React 18. Use createRoot instead.

Cause 1 of 3

react-dom is not installed in this project

1Check

Look for the folder in node_modules and for the dependency in package.json.

ls node_modules/react-dom/client.js
grep -n "react-dom" package.json

2Fix

Install react and react-dom together, which restores both.

npm install react react-dom

3Verify

The list shows both packages at the same version.

npm ls react react-dom

Confirmed by react.dev

Did this fix it?

Cause 2 of 3

An older React is installed, which has no react-dom/client

1Check

react-dom/client is the entry point introduced with the React 18 root API, so it is not available below version 18.

npm ls react react-dom

2Fix

Upgrade both packages, and switch main.jsx to the createRoot form.

npm install react@latest react-dom@latest

// src/main.jsx
import { createRoot } from 'react-dom/client'
import App from './App'

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

3Verify

Start the dev server and open the page.

npm run dev

Confirmed by react.dev

Did this fix it?

Cause 3 of 3

Dependencies were changed but Vite still uses its old pre-bundle

1Check

Vite caches pre-bundled dependencies in node_modules/.vite and reruns the step only when the lockfile or config changes.

ls node_modules/.vite

2Fix

Start the dev server with --force, or delete the cache folder.

rm -rf node_modules/.vite
npx vite --force

3Verify

The page loads with no error in the terminal or the console.

npx vite --force

Confirmed by vite.dev

Did this fix it?

How do I stop it coming back?

  • Install react and react-dom together and keep the two versions equal.
  • Run npm install after every git pull that changes package.json.
  • Commit the lockfile so every machine gets the same versions.

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.