heroku应用程序由于缺少模块而崩溃,但可在localhost上运行

时间:2018-12-16 08:11:19

标签: node.js heroku mongoose

我有一个已成功部署到heroku的应用程序,但是当我尝试访问它时,出现此屏幕... enter image description here

日志显示以下内容... enter image description here

我认为引起该问题的错误是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中,当我在本地主机上运行该软件包时,一切正常。如果您需要更多信息,请告诉我,谢谢您的阅读!

2 个答案:

答案 0 :(得分:0)

您要在代码中推送node_modules吗?如果是,请尝试删除该文件夹,然后让Heroku重新安装所有模块。

答案 1 :(得分:0)

结果是我没有将github连接到我的heroku。我正在推送到github,但是它没有更新heroku,所以我一直遇到同样的错误。这是我必须在heroku中启用的功能,然后我的编辑才真正显示在heroku中。 enter image description here

另一种选择是每次都在终端中输入git push heroku master

我要做的最后一件事是在终端机上输入heroku config:set MONGODB_URI='mongodb://<name>:<password>@ds123050.mlab.com:23050/ovodb',以便heroku访问我的环境变量。