Vite cannot find react-dom/client in main.jsx
Failed 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.
Fix it fast
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-dom2Match what you see, then jump to its fix
- 1
npm ls prints (empty) or a missing line for react-domreact-dom is not installed in this projectFix - 2
npm ls shows react or react-dom 17 or olderAn older React is installed, which has no react-dom/clientFix - 3
The package is in node_modules and at the right version, yet the error staysDependencies were changed but Vite still uses its old pre-bundleFix
- 1
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.json2Fix
Install react and react-dom together, which restores both.
npm install react react-dom3Verify
The list shows both packages at the same version.
npm ls react react-domConfirmed by react.dev
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-dom2Fix
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 devConfirmed by react.dev
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/.vite2Fix
Start the dev server with --force, or delete the cache folder.
rm -rf node_modules/.vite
npx vite --force3Verify
The page loads with no error in the terminal or the console.
npx vite --forceConfirmed by vite.dev
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:
- 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