heroku 应用程序由于缺少模块而崩溃,但可以在 localhost 上运行
Posted
技术标签:
【中文标题】heroku 应用程序由于缺少模块而崩溃,但可以在 localhost 上运行【英文标题】:heroku app crashes because of missing module, but works on localhost 【发布时间】:2019-05-16 22:49:59 【问题描述】:我有一个成功部署到 heroku 的应用程序,但是当我尝试访问它时,我得到了这个屏幕......
日志说如下...
我认为导致问题的错误是Error: Cannot find module 'mongoose'
。
这是我的 package.json 供参考...
"name": "ovo",
"version": "1.0.0",
"description": "see and sort OVO in real time!",
"main": "server.js",
"scripts":
"build": "webpack --config webpack.prod.config.js",
"dev": "concurrently -k \"npm run frontend\" \"npm run backend\"",
"frontend": "webpack -d --watch",
"backend": "nodemon server.js",
"start": "npm run build && NODE_ENV=production node server.js",
"test": "mocha --compilers js:babel-core/register ./test/**/*.js --require ignore-styles"
,
"engines":
"node": "6.11.0",
"npm": "5.0.3"
,
"repository":
"type": "git",
"url": "git+https://github.com/leojacoby/ovo.git"
,
"author": "",
"license": "ISC",
"dependencies":
"axios": "^0.17.1",
"babel-core": "^6.24.1",
"babel-loader": "^6.4.1",
"babel-preset-es2015": "^6.24.1",
"babel-preset-react": "^6.24.1",
"css-loader": "^0.28.0",
"enzyme": "^2.8.1",
"expect": "^1.20.2",
"express": "^4.15.2",
"immutability-helper": "^2.6.5",
"mocha": "^3.2.0",
"mongoose": "^5.4.0",
"node-sass": "^4.5.2",
"prop-types": "^15.6.0",
"rc-slider": "^8.6.0",
"rc-tooltip": "^3.7.0",
"react": "^15.5.4",
"react-addons-update": "^15.6.2",
"react-bootstrap-table": "^4.3.1",
"react-bootstrap-table-next": "^0.1.3",
"react-dom": "^15.5.4",
"react-rangeslider": "^2.2.0",
"react-redux": "^5.0.5",
"redux": "^3.7.2",
"redux-devtools": "^3.4.0",
"redux-devtools-dock-monitor": "^1.1.2",
"redux-devtools-log-monitor": "^1.3.0",
"sass-loader": "^6.0.3",
"style-loader": "^0.16.1",
"webpack": "^2.3.3"
,
"devDependencies":
"babel-eslint": "^7.2.2",
"concurrently": "^3.5.0",
"eslint": "^3.19.0",
"eslint-loader": "^1.9.0",
"eslint-plugin-jsx-a11y": "^4.0.0",
"eslint-plugin-react": "^6.10.3",
"eslint-watch": "^3.1.0",
"ignore-styles": "^5.0.1",
"nodemon": "^1.11.0",
"react-addons-test-utils": "^15.5.1",
"react-test-renderer": "^15.5.4",
"webpack-dev-middleware": "^1.10.1",
"webpack-dev-server": "^2.4.2",
"webpack-hot-middleware": "^2.18.0"
,
"bugs":
"url": "https://github.com/leojacoby/ovo/issues"
,
"homepage": "https://github.com/leojacoby/ovo#readme",
"directories":
"test": "test"
,
"keywords": []
“mongoose”npm 包在我的 package.json 中,当我在本地主机上运行它时一切正常。如果您想了解更多信息,请告诉我,感谢您的阅读!
【问题讨论】:
你的项目根目录中有package.json
吗?
是的 package.json
在我的根目录中
【参考方案1】:
原来我没有将我的 github 连接到我的 heroku。我正在推送到 github,但它没有更新 heroku,所以我一直遇到同样的错误。这是我必须在 heroku 中启用的,然后我的编辑实际上体现在 heroku 中。
另一种方法是每次在终端中输入git push heroku master
。
我要做的最后一件事是在终端中输入 heroku config:set MONGODB_URI='mongodb://<name>:<password>@ds123050.mlab.com:23050/ovodb'
,让 heroku 访问我的环境变量。
【讨论】:
【参考方案2】:您是否在代码中推送 node_modules?如果是,请尝试删除该文件夹并让 Heroku 重新安装所有模块。
【讨论】:
另外,请确保跟踪您的package-lock.json
或 yarn.lock
,以便 Heroku 可以安装您在开发中使用的依赖项的确切版本。
我的.gitignore
文件中有node_modules
和package-lock.json
,但我取出package-lock.json
然后再试一次,但还是不行。以上是关于heroku 应用程序由于缺少模块而崩溃,但可以在 localhost 上运行的主要内容,如果未能解决你的问题,请参考以下文章