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.
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.
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.
package-lock.json
file.npm install
command.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.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With