Last modified: Jun 26, 2025 By Alexander Williams

Fix Error: Cannot find module 'react-dom'

If you see the error Cannot find module 'react-dom', don't worry. This is a common issue in React projects. It happens when Node.js can't locate the react-dom package.

Why Does This Error Occur?

The error occurs because react-dom is missing from your project. This can happen if you forgot to install it or if there's an issue with your node_modules folder.

Other reasons include incorrect package.json setup or version conflicts. Similar errors like Cannot find module 'react' or Cannot find module 'eslint' follow the same pattern.

How to Fix the Error

1. Install react-dom

The simplest fix is to install the missing package. Run this command in your project directory:


npm install react-dom

If you're using Yarn, run:


yarn add react-dom

2. Check Your package.json

Ensure react-dom is listed in your dependencies. Open package.json and look for:


"dependencies": {
  "react-dom": "^18.2.0"
}

If it's missing, add it and run npm install again.

3. Delete node_modules and Reinstall

Sometimes the node_modules folder gets corrupted. Try this:


rm -rf node_modules
npm install

4. Check Your Import Statement

Make sure you're importing react-dom correctly:


import ReactDOM from 'react-dom/client'; // For React 18+

Or for older versions:


import ReactDOM from 'react-dom';

Common Mistakes

People often confuse react and react-dom. They are separate packages. You need both installed.

Another mistake is installing packages globally when they should be local. Always install project dependencies in your project folder.

Version Compatibility

Ensure your react and react-dom versions match. For example:


"react": "^18.2.0",
"react-dom": "^18.2.0"

Mismatched versions can cause errors. This is similar to issues with eslint-config-airbnb version conflicts.

Using Create React App

If you used Create React App, react-dom should be included automatically. If you get the error, try:


npx create-react-app my-app --template typescript

Conclusion

The Cannot find module 'react-dom' error is easy to fix. Most times, installing the package solves it. Always check your dependencies and version compatibility.

For similar module errors, check our guides on fixing prettier errors or other common Node.js module issues.