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.
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.
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 [email protected]Replace 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_modulesVersion 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.
Prop spreading could cause security issues
Prop spreading could cause security issues
Error: error:0308010C:digital envelope routines::unsupported
Error: error:0308010C:digital envelope routines::unsupported
React Hook "useEffect" is called conditionally. React Hooks must be called in the exact same order in every component render.
React Hook useEffect placed inside a condition
Hook can only be called inside the body of a function component
Hook can only be called inside the body of a function component
Rollup failed to resolve import during build
How to fix "Rollup failed to resolve import" in React