[英]Module not found: Can't resolve 'react' in 'C:\Users\USER\Desktop\test\src'
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我使用 create-react-app test 创建了一个名为文件夹的测试,并且在执行 npm 时成功创建文件夹后开始收到此错误
Failed to compile.
./src/index.js
Module not found: Can't resolve 'react' in 'C:\Users\USER\Desktop\test\src'
package.json包.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.我曾尝试删除 yarn.lock 文件然后安装 yarn 但错误未修复。
package-lock.json
file.package-lock.json
文件。npm install
command.npm install
命令。npm start
again.npm start
。 PS: You can also use pnpm
instead of npm
by installing its package via npm i -g pnpm
command. PS:您也可以通过
npm i -g pnpm
命令安装其包来使用pnpm
代替npm
。 pnpm package has some benefits compare to npm command that you can read the complete difference in this site .与 npm 命令相比,pnpm 包有一些好处,您可以在此站点中阅读完整的区别。
Replace this line of code替换这行代码
import DatePicker from "react-datepicker";
replace by替换为
import DatePicker from "../react-datepicker";
or else要不然
have to install packages必须安装软件包
npm install react-datepicker --save
If you are not using faker then remove from your index.js file如果你没有使用 faker,那么从你的 index.js 文件中删除
import Faker from 'faker';
Remove above line删除上面的行
I had encounter similar error, I wrote:我遇到过类似的错误,我写道:
import ReactDOM from "react-dom ";
instead of :代替 :
import ReactDOM from "react-dom";
Remove the extra space or check for any syntax error.删除多余的空间或检查任何语法错误。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.