首页 > 解决方案 > Heroku 上的 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

任何帮助将不胜感激,谢谢。

标签: node.jsherokudeploymentnodemon

解决方案


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

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

  1. 确认应用程序在本地运行,无论是否使用nodemon.
  2. 确保您的 Procfile 以大写字母开头P( https://devcenter.heroku.com/articles/procfile#procfile-format )
  3. web将您个人资料中的指令更新为npm start

如果上述更改不起作用,请执行以下操作:

  1. 导航到项目的根目录,然后按如下方式启动远程会话heroku ps:exec
  2. 进入应用程序的测功机后,运行npm ls. 如果这失败了,你的依赖没有被正确安装(这看起来像一个 Heroku 问题)
  3. 如果上述命令成功,请运行npm start以确认应用程序可以启动。

推荐阅读