Nodeoku在Heroku上启动错误

时间:2018-10-22 15:55:08

标签: node.js heroku deployment nodemon

部署到Heroku时遇到了相同的启动错误。我知道这与我的启动脚本有关,但我似乎无法确定问题所在。

我在应用启动时遇到此错误:

2018-10-22T15:31:04.927032+00:00 heroku[web.1]: Process exited with status 1
2018-10-22T15:31:04.944756+00:00 heroku[web.1]: State changed from starting to crashed
2018-10-22T15:31:04.946982+00:00 heroku[web.1]: State changed from crashed to starting
2018-10-22T15:31:04.804183+00:00 app[web.1]:
2018-10-22T15:31:04.804198+00:00 app[web.1]: > Backend@ start /app
2018-10-22T15:31:04.804200+00:00 app[web.1]: > nodemon -e js,graphql -x node -r dotenv/config src/index.js
2018-10-22T15:31:04.804202+00:00 app[web.1]:
2018-10-22T15:31:04.810881+00:00 app[web.1]: sh: 1: nodemon: not found
2018-10-22T15:31:04.817652+00:00 app[web.1]: npm ERR! file sh
2018-10-22T15:31:04.818091+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-10-22T15:31:04.818534+00:00 app[web.1]: npm ERR! errno ENOENT
2018-10-22T15:31:04.818822+00:00 app[web.1]: npm ERR! syscall spawn
2018-10-22T15:31:04.820778+00:00 app[web.1]: npm ERR! Backend@ start: `nodemon -e js,graphql -x node -r dotenv/config src/index.js`
2018-10-22T15:31:04.821033+00:00 app[web.1]: npm ERR! spawn ENOENT
2018-10-22T15:31:04.821320+00:00 app[web.1]: npm ERR!
2018-10-22T15:31:04.821464+00:00 app[web.1]: npm ERR! Failed at the Backend@ start script.
2018-10-22T15:31:04.821628+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-10-22T15:31:04.829156+00:00 app[web.1]:
2018-10-22T15:31:04.829411+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2018-10-22T15:31:04.829659+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2018-10-22T15_31_04_823Z-debug.log
2018-10-22T15:31:09.008630+00:00 heroku[web.1]: Starting process with command `npm start`
2018-10-22T15:31:12.142111+00:00 app[web.1]:
2018-10-22T15:31:12.142136+00:00 app[web.1]: > Backend@ start /app
2018-10-22T15:31:12.142138+00:00 app[web.1]: > nodemon -e js,graphql -x node -r dotenv/config src/index.js
2018-10-22T15:31:12.142140+00:00 app[web.1]:
2018-10-22T15:31:12.151638+00:00 app[web.1]: sh: 1: nodemon: not found
2018-10-22T15:31:12.157445+00:00 app[web.1]: npm ERR! file sh
2018-10-22T15:31:12.157635+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2018-10-22T15:31:12.157787+00:00 app[web.1]: npm ERR! errno ENOENT
2018-10-22T15:31:12.157931+00:00 app[web.1]: npm ERR! syscall spawn
2018-10-22T15:31:12.159057+00:00 app[web.1]: npm ERR! Backend@ start: `nodemon -e js,graphql -x node -r dotenv/config src/index.js`
2018-10-22T15:31:12.159155+00:00 app[web.1]: npm ERR! spawn ENOENT
2018-10-22T15:31:12.159323+00:00 app[web.1]: npm ERR!
2018-10-22T15:31:12.159423+00:00 app[web.1]: npm ERR! Failed at the Backend@ start script.
2018-10-22T15:31:12.159520+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2018-10-22T15:31:12.164017+00:00 app[web.1]:

因此,尽管已安装它,但找不到nodemon。这是我的package.json:

{
  "name": "Backend",
  "scripts": {
    "start": "nodemon -e js,graphql -x node -r dotenv/config src/index.js",
    "debug": "nodemon -e js,graphql -x node --inspect -r dotenv/config src/index.js",
    "playground": "graphql playground",
    "dev": "npm-run-all --parallel start playground"
  },
  "dependencies": {
    "bcryptjs": "2.4.3",
    "googleapis": "^27.0.0",
    "graphql-yoga": "1.12.0",
    "jsonwebtoken": "8.2.1",
    "multer": "^1.4.0",
    "node-schedule": "^1.3.0",
    "nodemailer": "^4.6.4",
    "prisma-binding": "1.5.17",
    "winston": "^2.4.2",
    "nodemon": "1.17.3"
  },
  "devDependencies": {
    "dotenv": "5.0.1",
    "graphql-cli": "2.15.9",
    "nodemon": "1.17.3",
    "npm-run-all": "4.1.2",
    "prisma": "^1.6.3"
  }
}

而我的procfile是web: node src/index.js

非常感谢您的帮助。

1 个答案:

答案 0 :(得分:1)

看来nodemon -e js,graphql -x node -r dotenv/config src/index.js被npm以外的其他人调用,这导致nodemon丢失的问题,无论实际上是否nodemon都存在。

您可以采取以下措施找出问题的根本原因:

  1. 确认该应用在本地运行,有无nodemon
  2. 确保您的Procfile以大写的Phttps://devcenter.heroku.com/articles/procfile#procfile-format)开头
  3. 将个人资料中的web指令更新为npm start

如果上述更改无效,请执行以下操作:

  1. 导航到项目的根目录,然后按以下步骤启动远程会话:heroku ps:exec
  2. 一旦在应用程序的dyno中运行npm ls。如果失败,则说明您的依赖项未正确安装(这似乎是Heroku问题)
  3. 如果上述命令成功执行,请运行npm start以确认该应用程序可以启动。