简体   繁体   English

找不到模块:无法解析“C:\\Users\\USER\\Desktop\\test\\src”中的“react”

[英]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 但错误未修复。

  1. Remove package-lock.json file.删除package-lock.json文件。
  2. Run npm install command.运行npm install命令。
  3. Try to execute 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.

相关问题 找不到模块:无法解析“C:\Users\user\Desktop\react-challenge\sample\src”中的“./App” - Module not found : Can't resolve './App' in 'C:\Users\user\Desktop\react-challenge\sample\src' 未找到模块:无法解析“C:\Users\USER\auth_form_react\src”中的“firebaseui” - Module not found: Can't resolve 'firebaseui' in 'C:\Users\USER\auth_form_react\src' 找不到模块:无法解析“C:\\Users\\Admin\\Desktop\\MyApp\\frontend\\src\\components”中的“axios” - Module not found: Can't resolve 'axios' in 'C:\Users\Admin\Desktop\MyApp\frontend\src\components' ./src/Firebase.js 模块未找到:无法解析“C:\\Users\\HP\\Desktop\\React\\clone\\disney-plus-clone\\src”中的“firebase” - ./src/Firebase.js Module not found: Can't resolve 'firebase' in 'C:\Users\HP\Desktop\React\clones\disney-plus-clone\src' 未找到模块:无法解析“C:\Users\Mohammad\Desktop\Chat-System\src\components”中的“..src/firebase.js” - Module not found: Can't resolve '..src/firebase.js' in 'C:\Users\Mohammad\Desktop\Chat-System\src\components' 找不到模块:无法解析“C:\react-test\src\components\content”中的“node_modules/react” - Module not found: Can't resolve 'node_modules/react' in 'C:\react-test\src\components\content' [React Webpack]:找不到模块:错误:无法解析 'C:\Users\...' 中的 'src/views/UserList' - [React Webpack]: Module not found: Error: Can't resolve 'src/views/UserList' in 'C:\Users\…' &#39;react&#39; - 运行 npm start 后,它给出 ./src/index.js Module not found: Can&#39;t resolve &#39;react&#39; in &#39;C:\\Users\\...\\src&#39; 错误 - 'react' - After run npm start it gives ./src/index.js Module not found: Can't resolve 'react' in 'C:\Users\...\src' error 找不到模块:无法解析“C:\Users\MSI\Desktop\cake-app\src\Components\Product”中的“../../images/jelly” - Module not found: Can't resolve '../../images/jelly' in 'C:\Users\MSI\Desktop\cake-app\src\Components\Product' 未找到模块:错误:无法解析 'C:\Users\bug\Desktop\wp-test\node_modules\react-render-html\node_modules\parse5\lib\serializer 中的 'util' - Module not found: Error: Can't resolve 'util' in 'C:\Users\bug\Desktop\wp-test\node_modules\react-render-html\node_modules\parse5\lib\serializer
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM