Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Module not found: Can't resolve 'react' in 'C:\Users\USER\Desktop\test\src'

Tags:

I had created a test named folder using create-react-app test and after successful creation of folder when doing npm start getting this error

Failed to compile.

./src/index.js
Module not found: Can't resolve 'react' in 'C:\Users\USER\Desktop\test\src'

package.json

{
  "name": "test",
  "version": "0.1.0",
  "private": true,
  "dependencies": {
    "react": "^16.6.3",
    "react-dom": "^16.6.3",
    "react-scripts": "2.1.1"
  },
  "scripts": {
    "start": "react-scripts start",
    "build": "react-scripts build",
    "test": "react-scripts test",
    "eject": "react-scripts eject"
  },
  "eslintConfig": {
    "extends": "react-app"
  },
  "browserslist": [
    ">0.2%",
    "not dead",
    "not ie <= 11",
    "not op_mini all"
  ]
}

I had tried removing yarn.lock file then yarn install but error is not fixed.

like image 721
Shubham Kumar Avatar asked Dec 02 '18 11:12

Shubham Kumar


People also ask

How do I fix module not found in react?

To solve the "Module not found: Can't resolve" error in React, make sure to install the package from the error message if it's a third-party package, e.g. npm i somePackage . If you got the error when importing local files, correct your import path.

How do you fix react-scripts is not recognized as an internal or external command?

To solve the error "react-scripts is not recognized as an internal or external command, operable program or batch file", open your terminal in your project's root directory and install the react-scripts package by running npm install react-scripts and clear your npm cache if necessary.


1 Answers

  1. Remove package-lock.json file.
  2. Run npm install command.
  3. Try to execute npm start again.

PS: You can also use pnpm instead of npm by installing its package via npm i -g pnpm command. pnpm package has some benefits compare to npm command that you can read the complete difference in this site.

like image 183
Mostafa Ghadimi Avatar answered Oct 04 '22 06:10

Mostafa Ghadimi