How to fix Module not found: Can't resolve 'react-dom' in React
This error occurs when React cannot locate the react-dom package in your project dependencies. It typically happens during the build process or when starting the development server, preventing your React application from rendering.
Quick fix
Fixes Module not found: Can't resolve 'react-dom'
npm install react-dom react- Install react-dom package
- Verify package.json contains react-dom
- Clear installation cache and reinstall
- Check for correct import statements
npm install react-dom reactModule not found: Can't resolve 'react-dom'
npm install react-dom reactWhat this error means
This error indicates that the React bundler (typically Webpack or Vite) cannot find the react-dom package when trying to resolve imports in your code. The react-dom package is a critical dependency that provides DOM-specific methods for React, including the ability to render components in the browser. The error occurs during the module resolution phase of the build process. When your code imports from 'react-dom' or 'react-dom/client', the bundler searches through your node_modules directory to find the package. If the package is missing, not properly installed, or if there are permission issues, this error will be thrown. This is one of the most common setup errors in React projects, often occurring immediately after cloning a repository, upgrading dependencies, or when moving projects between environments.
Typical symptoms
- Build process fails with "Module not found" error
- Development server crashes on startup
- Error message specifically mentions "Can't resolve 'react-dom'"
- Application fails to render with blank screen
- Console shows module resolution errors
- CI/CD pipeline fails during build step
Common causes
- react-dom package was never installed in the project
- node_modules directory is missing or incomplete
- package-lock.json or yarn.lock is out of sync with package.json
- Version mismatch between React and react-dom packages
- Corrupted npm cache or installation
- Incorrect import path (e.g., importing from 'react-dom/client' without React 18)
- Missing dependencies after cloning a repository
- File system permissions preventing package installation
How to fix "Module not found: Can't resolve 'react-dom'"
The most common fix is to install or reinstall the react-dom package. Run this command in your project root:
npm install react-dom reactOr if using Yarn:
yarn add react-dom reactOr with pnpm:
pnpm add react-dom reactThis installs both react and react-dom to ensure version compatibility. After installation, restart your development server.
Check that react-dom is listed in your package.json dependencies:
{
"dependencies": {
"react": "^18.2.0",
"react-dom": "^18.2.0"
}
}The versions of react and react-dom should match. If react-dom is missing or has a different major version, update it:
npm install react-dom@18.2.0Replace with the version that matches your React version.
If the package appears to be installed but the error persists, clear your installation cache:
# Delete node_modules and lock files
rm -rf node_modules package-lock.json
# Clear npm cache
npm cache clean --force
# Reinstall all dependencies
npm installFor Yarn:
rm -rf node_modules yarn.lock
yarn cache clean
yarn installAfter reinstalling, restart your development server and IDE.
Verify your imports match your React version. For React 18+, the import should be:
// React 18 and later
import { createRoot } from 'react-dom/client';
const root = createRoot(document.getElementById('root'));
root.render(<App />);For React 17 and earlier:
// React 17 and earlier
import ReactDOM from 'react-dom';
ReactDOM.render(<App />, document.getElementById('root'));If you're importing 'react-dom/client' but using React 17, either upgrade React or change to the legacy API.
Check that the react-dom package actually exists in your node_modules:
# Check if react-dom directory exists
ls node_modules/react-dom
# Verify react-dom package.json
cat node_modules/react-dom/package.jsonIf the directory is missing or corrupted, reinstall:
npm install react-dom --forceAlso check file permissions if you're on Linux/macOS:
sudo chown -R $USER node_modulesAdvanced notes
Version Compatibility: React 18 introduced breaking changes in the react-dom API. Projects created with Create React App 5+ use the new react-dom/client entry point. If you're upgrading from React 17, you must either update your index.js to use createRoot or add both react-dom versions to your dependencies.
Monorepo Considerations: In monorepo setups (using Yarn workspaces, pnpm workspaces, or npm workspaces), ensure react-dom is hoisted correctly. You may need to add it to the root package.json or configure hoisting settings.
Webpack Module Resolution: If using a custom Webpack config, verify the resolve.modules setting includes node_modules. Some configurations override this and break module resolution:
// webpack.config.js
module.exports = {
resolve: {
modules: ['node_modules', path.resolve(__dirname, 'src')]
}
};Docker and CI/CD: In containerized environments, ensure your Dockerfile or CI configuration runs npm install before the build step. Missing this step is a common cause of this error in deployment pipelines. Also consider using npm ci instead of npm install for more reliable installs in CI environments.
Peer Dependency Issues: Some packages have peer dependencies on specific react-dom versions. Check npm ls react-dom to identify version conflicts. Use npm install --legacy-peer-deps if you encounter peer dependency errors during installation.
Frequently asked questions
- What does "Module not found: Can't resolve 'react-dom'" mean?
- This error indicates that the React bundler (typically Webpack or Vite) cannot find the react-dom package when trying to resolve imports in your code. The react-dom package is a critical dependency that provides DOM-specific methods for React, including the ability to render components in the browser. The error occurs during the module resolution phase of the build process.
- How do I fix "Module not found: Can't resolve 'react-dom'"?
- This error occurs when React cannot locate the react-dom package in your project dependencies. It typically happens during the build process or when starting the development server, preventing your React application from rendering.
- What causes "Module not found: Can't resolve 'react-dom'"?
- react-dom package was never installed in the project node_modules directory is missing or incomplete package-lock.json or yarn.lock is out of sync with package.json
- Is the "Module not found: Can't resolve 'react-dom'" error serious?
- Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.