在 heroku 上部署节点应用程序触发与 nodemon 相关的错误

Deploying node app on heroku firing errors related to nodemon

我正在尝试 运行 我在 heroku 中的节点应用程序,但我收到与 nodemon 依赖相关的错误。

2018-12-16T21:32:51.891208+00:00 app[web.1]: sh: 1: nodemon: not found
2018-12-16T21:32:51.895084+00:00 app[web.1]: npm ERR! file sh
2018-12-16T21:32:51.895380+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-12-16T21:32:51.895627+00:00 app[web.1]: npm ERR! errno ENOENT
2018-12-16T21:32:51.895865+00:00 app[web.1]: npm ERR! syscall spawn
2018-12-16T21:32:51.896987+00:00 app[web.1]: npm ERR! turktutor_backend@1.0.0 start: `nodemon --watch`
2018-12-16T21:32:51.897151+00:00 app[web.1]: npm ERR! spawn ENOENT

我的 package.json 是这样的:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "nodemon --watch"
  },
"dependencies": {
    "bcrypt": "^3.0.2",
    "body-parser": "^1.18.3",
    "express": "^4.16.4",
    "express-validator": "^5.3.0",
    "googleapis": "^27.0.0",
    "jsonwebtoken": "^8.4.0",
    "mongoose": "^5.3.14",
    "mongoose-unique-validator": "^2.0.2",
    "nodemailer": "^4.7.0"
  },
  "devDependencies": {
    "morgan": "^1.9.1",
    "nodemon": "^1.18.7"
  }

我试着按照这个 link that requires changing "Procfile" file, but heroku says that Procfile is no longer required for Node.js apps source

中的解决方案

我想知道是否需要通过某些命令在 heroku 服务器中安装我的 devDependencies!

所以请帮忙解决这个问题?

默认情况下,heroku 只安装非开发依赖,这就是找不到 nodemon 的原因。您可以在 heroku 仪表板上定义环境变量,但我认为它不会安装开发依赖项。在生产中你不需要 nodemon,你的想法是什么?

我发现 heroku 运行s 默认情况下在生产环境中,所以它不会安装开发依赖项所以我在我的 package.json 中创建了两个不同的 npm 脚本脚本:

"scripts": {
    "test": "echo \"Error: no test specified\" && exit 1",
    "start": "node index.js",
    "start:dev": "nodemon --watch"
},

当我想 运行 本地项目时,我 运行 npm run start:dev 所以它通过 nodemon 加载 index.js,而在 heroku npm start [=默认为 20=]s 并从普通节点命令加载 index.js。