大家好,我是heroku上的新手,
如果我从github存储库中克隆并运行> npm install并> npm在计算机上正常运行,但在我的heroku应用程序上则显示错误:
无法编译./node_modules/bootstrap/dist/js/bootstrap.js模块 找不到:无法解析“ popper.js” '/ app / node_modules / bootstrap / dist / js'
Heroku应用:https://nfq-barber-shop.herokuapp.com/ Github仓库:https://github.com/ezopas/nfq-barber-shop 我尝试运行以下命令:
npm install bootstrap -D
npm install jquery -D
npm install popper.js -D
但是仍然是相同的错误。我该怎么办?我的应用程序在其他计算机上完全正常运行(npm start)。
package.json:
{
"name": "nfq-barber-shop-app",
"version": "0.1.0",
"private": true,
"dependencies": {
"axios": "^0.18.0",
"bootstrap": "^4.3.1",
"font-awesome": "^4.7.0",
"fullcalendar": "^3.10.0",
"fullcalendar-reactwrapper-with-scheduler": "^1.1.0",
"jquery.nicescroll": "^3.7.6",
"moment": "^2.24.0",
"nav-scroll-spy": "^1.0.2",
"node-sass": "^4.11.0",
"react": "^16.8.1",
"react-dom": "^16.8.1",
"react-router": "^4.3.1",
"react-router-dom": "^4.3.1",
"react-router-redux": "^4.0.8",
"react-scripts": "2.1.5",
"redux": "^4.0.1",
"sweetalert": "^2.1.2"
},
"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"
],
"devDependencies": {
"jquery": "^3.3.1",
"popper.js": "^1.14.7"
}
}
答案 0 :(得分:1)
TLDR
devDependencies
中的模块移至dependencies
部分NPM_CONFIG_PRODUCTION
设置为false 说明
Heroku为减少项目的捆绑包输出,在设置项目时未安装devDependencies
。
Node应用程序开发的一般规则是,所有不需要对应用程序的运行做出贡献的模块都必须进入devDependencies
,而所有确实参与dependencies
的模块>
从package.json
的外观来看,由于popper和jQuery do 属于devDependencies
部分,因此您不必在dependencies
中放置任何内容。
您也可以在Heroku中将NPM_CONFIG_PRODUCTION
变量设置为false,但这不是推荐的方法,因为从技术上讲,这使应用程序不是成为生产应用程序
答案 1 :(得分:0)
转到引导程序文档网站并选择您正在使用的适当版本的引导程序。 对于 bootstrap 4,从 docs 中,将启动模板中的 bootstrapCDN 链接添加到您的 index.html 文件中。
对于这个特定问题,添加
lib
到您的 index.html。
注意:检查脚本的适当版本。