node.js 第一次 Heroku 部署失败 `error code=H10`

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14322989/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-02 16:56:36  来源:igfitidea点击:

First Heroku deploy failed `error code=H10`

node.jsherokuexpress

提问by ilyo

I deployed my app to Heroku. It's a node.js + express + socket.io app and this is the package.jsonfile

我将我的应用程序部署到 Heroku。这是一个 node.js + express + socket.io 应用程序,这是package.json文件

{
  "name": "game_test",
  "author": "Ilya",
  "description": "A test app for our board game",
  "version": "0.0.1",
  "private": true,
  "scripts": {
    "start": "node app"
  },
  "dependencies": {
    "express": "3.0.6",
    "jade": "*",
    "socket.io" : "*"
  },
 "engines": {
      "node": "0.8.14"
  }
}

This is the log I get:

这是我得到的日志:

heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/ host=game-test-1.herokuapp.com fwd=37.26.146.185 dyno= queue= wait= connect= service= status=503 bytes=
heroku[router]: at=error code=H10 desc="App crashed" method=GET path=/favicon.ico host=game-test-1.herokuapp.com fwd=37.26.146.185 dyno= queue= wait= connect= service= status=503 bytes=

What does it mean?

这是什么意思?

回答by Martin Schaer

Found solution for me here: Heroku + node.js error (Web process failed to bind to $PORT within 60 seconds of launch)

在这里为我找到了解决方案:Heroku + node.js 错误(Web 进程无法在启动后 60 秒内绑定到 $PORT)

In my case my app crashed because I was hard setting the PORT, instead of using the port that heroku dinamicaly sets, which can be accessed with process.env.PORT

在我的情况下,我的应用程序崩溃了,因为我很难设置端口,而不是使用 heroku dinamicaly 设置的端口,可以通过访问 process.env.PORT

app.listen(process.env.PORT || 3000, function(){
  console.log("Express server listening on port %d in %s mode", this.address().port, app.settings.env);
});

回答by clarenswd

I just had a similar issue with my app, I got the issue after a migration of the DB, after trying many options, the one that helped me was this:

我的应用程序刚刚遇到了类似的问题,在迁移数据库后遇到了这个问题,在尝试了许多选项后,对我有帮助的是:

heroku restart

(Using Heroku toolbelt for mac)

(在 Mac 上使用 Heroku 工具带)

回答by Mahesh Singh Chouhan

In my case, i found same error because there is version difference of node and npm on my local machine and defined in package.json version.

就我而言,我发现了同样的错误,因为我的本地机器上存在 node 和 npm 的版本差异,并在 package.json 版本中定义。

"engines": {
  "node": "0.8",
  "npm": "1.2.x"
}

when i check using

当我检查使用

node --version : v0.10.41
npm --version : 1.4.29

when i update my package.json to

当我将 package.json 更新为

 "engines": {
  "node": "0.10.41",
  "npm": "1.4.29"
}

It works fine :)

它工作正常:)

回答by Ewertom Moraes

in my case adding process.env.PORT || 3000to my http server script, resolved. My heroku log reported 'H20' error and 503 http status.

在我的情况下,添加process.env.PORT || 3000到我的 http 服务器脚本中,已解决。我的 heroku 日志报告了“H20”错误和 503 http 状态。

回答by Arian Nargesi

I had this issue, the only problem was my Procfile my Procfile was like this

我有这个问题,唯一的问题是我的 Procfile 我的 Procfile 是这样的

web : node index.js

and I changed to

我改为

web:node index.js

the only problem was spaces

唯一的问题是空格

回答by Sina Meraji

In my case, my Procfile was pointing to the wrong file (bot.js which I previously used) so once I updated it, the error was gone.

就我而言,我的 Procfile 指向错误的文件(我以前使用过的 bot.js),所以一旦我更新它,错误就消失了。

回答by Martin De Simone

I faced this same problem and none of the answers above helped me. What i did was run:

我遇到了同样的问题,上面的答案都没有帮助我。我所做的是运行:

node --version

and in the package.json add the engines section with your node version:

并在 package.json 中使用您的节点版本添加引擎部分:

{
  "name": "myapp",
  "description": "a really cool app",
  "version": "1.0.0",
  "engines": {
    "node": "6.11.1"
  }
}

回答by littlebotrj

upon using hapi18, I find taking out the "host" field and setting the port to:

使用 hapi18 后,我发现取出“主机”字段并将端口设置为:

port: process.env.PORT || 5000did the trick.

port: process.env.PORT || 5000成功了。

回答by lindsaymacvean

Also check your database connection. I forgot to change my database connection from localhost and this crashed my app once it was pushed to heroku.

还要检查您的数据库连接。我忘记从 localhost 更改我的数据库连接,一旦它被推送到 heroku,我的应用程序就会崩溃。

回答by Forest baba

In my own case, i got this error because i refuse to add a Procfile to my node js app and my "main": "app.js" was initially pointing to another js file as main. so doing these chnages get it fixed for me

在我自己的情况下,我收到此错误是因为我拒绝将 Procfile 添加到我的节点 js 应用程序中,而我的“main”:“app.js”最初指向另一个 js 文件作为主文件。所以做这些改变为我修复它