How to fix Module not found: Can't resolve 'react' in React

ReactBEGINNERHIGHUpdated Dec 11, 2025ยท 96 views

This error occurs when your build tool or development server cannot locate the React library in your project. It typically happens when React is not installed, node_modules is missing or corrupted, or your package.json dependencies are incomplete. Resolving this requires ensuring React is properly installed and your project's dependency tree is intact.

Quick fix

Fixes Module not found: Can't resolve 'react'

ls -la
# You should see package.json in the output

pwd
# Verify this is your project's root directory
  1. Verify you are in the correct directory
  2. Check if React is listed in package.json
  3. Install React and React DOM
  4. Perform a clean installation of all dependencies
react โ€” error
ls -la
# You should see package.json in the output
pwd
# Verify this is your project's root directory
Module not found: Can't resolve 'react'

What this error means

When webpack, Vite, or another bundler tries to compile your project, it needs to find all imported modules. The error "Module not found: Can't resolve 'react'" means the build tool cannot locate the React library that your code is trying to import. This happens during the module resolution phase, where the bundler searches for packages in the node_modules directory based on your import statements. If React is not installed, the node_modules folder is missing, or the package installation was interrupted or corrupted, the bundler will fail to find React and throw this error. This is a critical dependency error that prevents your project from building or running. The bundler expects to find React installed as a dependency in your project, and when it cannot locate the module, compilation halts immediately. For React projects, both the 'react' and 'react-dom' packages are essential dependencies. The error can also occur if you're running build commands from the wrong directory (not where package.json exists), or if your package manager's cache is corrupted.

Typical symptoms

  • Build process fails with "Module not found: Can't resolve 'react'" error
  • Development server crashes immediately when trying to start
  • Error occurs during npm run build or npm start
  • Similar errors for react-dom or other React-related packages
  • Project worked previously but now fails after cloning or pulling changes
  • Error appears after deleting node_modules or package-lock.json
  • npm install completes but the error persists
  • Import statements for React are highlighted as errors in your IDE

Common causes

  1. React is not listed in package.json dependencies or was accidentally removed
  2. node_modules directory is missing because npm install was not run after cloning the project
  3. Package installation was interrupted or corrupted, leaving an incomplete node_modules folder
  4. package-lock.json or yarn.lock is out of sync with package.json
  5. Running npm commands from the wrong directory (not the project root where package.json lives)
  6. npm cache is corrupted, causing installation failures
  7. Incorrect React version specified in package.json that cannot be resolved
  8. Workspace or monorepo configuration issue where React is not accessible to the current package
  9. Using a legacy npm version that has known issues with dependency resolution

How to fix "Module not found: Can't resolve 'react'"

1Verify you are in the correct directory

Ensure your terminal is in the project root directory where package.json is located. List the contents of the current directory and confirm package.json exists:

bash
ls -la
# You should see package.json in the output

pwd
# Verify this is your project's root directory

If package.json is not in the current directory, navigate to the correct directory using cd before proceeding.

2Check if React is listed in package.json

Open your package.json file and verify that "react" is listed under dependencies. It should look like this:

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

If React is missing from dependencies, add it manually or proceed to the next step to install it.

3Install React and React DOM

Install React and react-dom using npm or yarn. This will add them to package.json and create/update node_modules:

bash
npm install react react-dom

# Or if using yarn:
yarn add react react-dom

# Or if using pnpm:
pnpm add react react-dom

After installation completes, try running your development server or build command again.

4Perform a clean installation of all dependencies

If installing React did not resolve the issue, perform a complete clean reinstall. This removes potentially corrupted files and rebuilds your dependency tree:

bash
# Remove node_modules and lock file
rm -rf node_modules
rm -f package-lock.json
# Or for yarn: rm -f yarn.lock
# Or for pnpm: rm -f pnpm-lock.yaml

# Clear npm cache
npm cache clean --force

# Reinstall all dependencies
npm install

# Or for yarn:
yarn install

# Or for pnpm:
pnpm install

This forces a fresh installation of all packages from scratch.

5Verify your import statements are correct

Check that your import statements for React are formatted correctly. Common mistakes include typos or incorrect casing:

javascript
// CORRECT - lowercase "react"
import React from 'react';
import { useState } from 'react';

// WRONG - uppercase "React" in import path
import React from 'React'; // This will fail

// WRONG - incorrect module name
import React from 'reactjs'; // No such package

Ensure all files importing React use the correct lowercase 'react' module name.

6Check for workspace or monorepo configuration issues

If you are using a monorepo (with tools like Lerna, Nx, or Turborepo) or yarn/pnpm workspaces, ensure React is installed in the correct workspace package:

bash
# For yarn workspaces, install in specific package:
yarn workspace my-app add react react-dom

# For pnpm workspaces:
pnpm add react react-dom --filter my-app

# Alternatively, install in root for all packages:
pnpm add react react-dom -w

Verify your workspace configuration in package.json or the workspace root configuration file.

7Update npm to the latest version

Older versions of npm have known dependency resolution bugs. Update npm to the latest version:

bash
npm install -g npm@latest

# Verify the update
npm --version

After updating npm, delete node_modules and package-lock.json again, then run npm install.

8Restart your development server and IDE

After installing dependencies, completely restart your development server and IDE:

bash
# Stop the dev server (Ctrl+C)

# Start it again
npm run dev
# Or: npm start
# Or: yarn dev

Also close and reopen your code editor (VS Code, WebStorm, etc.) to ensure it reloads the updated node_modules.

Advanced notes

In some edge cases, this error can occur with Create React App projects when there is a peer dependency conflict or when using incompatible versions of React and react-dom. Always ensure React and react-dom have matching version numbers. If you are using TypeScript, you may also need to install @types/react and @types/react-dom as dev dependencies. For Next.js projects, React is automatically installed and managed by Next.js itself, so this error is less common but can still occur if dependencies are manually modified. If you encounter this error in a Docker container, ensure your Dockerfile includes the npm install step after copying package.json and package-lock.json. For projects using module resolution path mapping (like TypeScript paths or webpack aliases), verify that your configuration does not interfere with resolving the react package from node_modules. If you are migrating from an older React version, check for breaking changes in the React changelog that might affect your dependencies. The "Can't resolve" message is generic and applies to any missing module, so these troubleshooting steps work for other packages as well.

Frequently asked questions

What does "Module not found: Can't resolve 'react'" mean?
When webpack, Vite, or another bundler tries to compile your project, it needs to find all imported modules. The error "Module not found: Can't resolve 'react'" means the build tool cannot locate the React library that your code is trying to import. This happens during the module resolution phase, where the bundler searches for packages in the node_modules directory based on your import statements.
How do I fix "Module not found: Can't resolve 'react'"?
This error occurs when your build tool or development server cannot locate the React library in your project. It typically happens when React is not installed, node_modules is missing or corrupted, or your package.json dependencies are incomplete. Resolving this requires ensuring React is properly installed and your project's dependency tree is intact.
What causes "Module not found: Can't resolve 'react'"?
React is not listed in package.json dependencies or was accidentally removed node_modules directory is missing because npm install was not run after cloning the project Package installation was interrupted or corrupted, leaving an incomplete node_modules folder
Is the "Module not found: Can't resolve 'react'" error serious?
Yes. This is a high-severity error that usually blocks work until it is fixed, but the steps above resolve it.

Official resources & further reading