Heroku 上的 nodemon 启动错误
Posted
技术标签:
【中文标题】Heroku 上的 nodemon 启动错误【英文标题】:nodemon start errors on Heroku 【发布时间】:2019-03-26 18:18:39 【问题描述】:我在部署到 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】:看起来nodemon -e js,graphql -x node -r dotenv/config src/index.js
正在被 npm 以外的其他东西调用,这导致了nodemon
丢失的问题,无论nodemon
是否实际存在。
您可以采取以下措施来找出问题的根本原因:
-
确认应用在本地运行,无论有无
nodemon
。
确保您的 Procfile 以大写的 P
(https://devcenter.heroku.com/articles/procfile#procfile-format) 开头
将您个人资料中的web
指令更新为npm start
如果上述更改不起作用,请执行以下操作:
-
导航到项目的根目录,然后按如下方式启动远程会话:
heroku ps:exec
。
进入应用的测功机后,运行npm ls
。如果失败,则说明您的依赖项没有正确安装(这看起来像是 Heroku 问题)
如果上述命令成功,请运行npm start
以确认应用可以启动。
【讨论】:
感谢您的回答。我实际上发现了问题(我未能将更新的 package.lock 文件推送到 heroku),但我发现你的答案可以帮助其他人解释和明确步骤。以上是关于Heroku 上的 nodemon 启动错误的主要内容,如果未能解决你的问题,请参考以下文章
Heroku 无法启动我的节点应用程序,因为它试图用 nodemon 来做
错误 R10(启动超时)-> Web 进程未能在启动后 90 秒内绑定到 $PORT(Heroku 上的 Java Discord 机器人)
在与 nodemon 相关的 heroku 触发错误上部署节点应用程序
Node报错处理:[nodemon] app crashed - waiting for file changes before starting...