从github进行npm安装:找不到模块:无法解析'react-big-calendar'

时间:2019-02-07 08:36:42

标签: reactjs npm-install node-modules react-big-calendar

我必须在react-big-calendar模块上进行一些更改,因此我在github上创建了该项目,进行了修改并推送。然后,我使用以下命令来安装新软件包:

npm install https://github.com/wafa-yahyaoui/react-big-calendar/tarball/master --save

该软件包在package.json的依赖项中进行了计算:

"dependencies": {
"@babel/runtime": "7.0.0-beta.55",
"@fortawesome/fontawesome-svg-core": "^1.2.10",
"@fortawesome/free-solid-svg-icons": "^5.6.1",
"@fortawesome/react-fontawesome": "^0.1.3",
"@material-ui/core": "^3.6.2",
"@material-ui/icons": "^2.0.3",
"@types/googlemaps": "3.30.11",
"@types/markerclustererplus": "2.1.33",
"ajv": "6.5.2",
"axios": "^0.18.0",
"bootstrap": "^4.1.3",
"chartist": "^0.11.0",
"classnames": "2.2.6",
"emotion": "^10.0.5",
"enhanced-resolve": "^3.4.1",
"globalize": "^1.4.0",
"history": "^4.7.2",
"iban": "0.0.11",
"jwt-decode": "^2.2.0",
"moment": "2.22.2",
"perfect-scrollbar": "1.4.0",
"react": "^16.6.3",
"react-big-calendar": "https://github.com/wafa-yahyaoui/react-big-calendar/tarball/master",
"react-bootstrap-sweetalert": "^4.4.1",
"react-chartist": "^0.13.1",
"react-datetime": "^2.16.3",
"react-dom": "^16.6.3",
"react-facebook-pixel": "^0.1.2",
"react-ga": "^2.5.6",
"react-google-maps": "^9.4.5",
"react-jvectormap": "0.0.3",
"react-nouislider": "2.0.1",
"react-redux": "^5.1.1",
"react-router": "4.3.1",
"react-router-dom": "^4.3.1",
"react-router-redux": "^5.0.0-alpha.9",
"react-scripts": "1.1.4",
"react-spinners": "^0.4.7",
"react-swipeable-views": "0.12.15",
"react-table": "6.8.6",
"react-tagsinput": "3.19.0",
"react-transition-group": "^1.2.1",
"reactstrap": "^6.5.0",
"redux": "^4.0.1",
"redux-api-middleware": "^2.3.0",
"redux-persist": "^5.10.0",
"redux-persist-transform-filter": "0.0.18",
"redux-thunk": "^2.3.0",
"universal-cookie": "^3.0.7"}

我删除了node_modules文件夹,运行了npm install,但是在运行npm start时出现了此错误:

./src/containers/apartments/calendar.js    
Module not found: Can't resolve 'react-big-calendar' in 
'/Users/wafayahyaoui/homereact/src/containers/apartments'

calendar.js文件上的导入看起来像这样:

import React from "react";
import BigCalendar from "react-big-calendar";

如果导入错误,可能是什么原因?谢谢

2 个答案:

答案 0 :(得分:4)

我面临着同样的问题。花了3-4个小时才能弄清问题所在。这是一个解决方案。

  • 运行命令-npm运行构建-构建dist和lib文件夹。
  • 从.gitignore文件中删除dist和lib。
  • 输入您的代码。

如果您仔细查看package-lock.json,则有一行"main": "lib/index.js"指向lib文件夹。但是,当您分叉react-big-calendar存储库时,此存储库中没有lib文件夹,只有src文件夹。

因此很明显,首先您必须构建代码并将其推送到您的仓库中。

答案 1 :(得分:0)

我遇到了类似的问题,所以也许对某人会有帮助。 main的{​​{1}}属性指向无法访问的已生成文件,因此我添加了一个package.json脚本来运行发布包之前的构建。

prepare