【问题标题】:Deploying a node.js app (discord.jd bot) on Heroku causing an error在 Heroku 上部署 node.js 应用程序(discord.jd bot)导致错误
【发布时间】:2020-11-29 22:45:52
【问题描述】:

我正在尝试在 heroku 上部署一个不和谐机器人。它工作大约 1-2 分钟,然后出现错误

2020-08-10T10:05:17.228802+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-10T10:05:17.246146+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-10T10:05:17.307500+00:00 heroku[web.1]: Process exited with status 137
2020-08-10T10:05:17.347445+00:00 heroku[web.1]: State changed from starting to crashed

(完整日志):

2020-08-10T10:04:19.372794+00:00 app[web.1]: 
2020-08-10T10:04:19.372804+00:00 app[web.1]: > arepee-bot@1.0.0 start /app
2020-08-10T10:04:19.372804+00:00 app[web.1]: > node index.js
2020-08-10T10:04:19.372804+00:00 app[web.1]: 
2020-08-10T10:04:20.468443+00:00 app[web.1]: Bot [welcomeMessage.js] is ready!
2020-08-10T10:04:30.643838+00:00 app[web.1]: Bot [index.js] is ready!
2020-08-10T10:05:17.228802+00:00 heroku[web.1]: Error R10 (Boot timeout) -> Web process failed to bind to $PORT within 60 seconds of launch
2020-08-10T10:05:17.246146+00:00 heroku[web.1]: Stopping process with SIGKILL
2020-08-10T10:05:17.307500+00:00 heroku[web.1]: Process exited with status 137
2020-08-10T10:05:17.347445+00:00 heroku[web.1]: State changed from starting to crashed

package.json 中的start 命令为:node index.js

Procfile 是:

worker: node index.js

index.js 是:

const Discord = require("discord.js")
const client = new Discord.Client()
const welcomeMessage = require("./welcomeMessage")

client.on("ready", () => {
    console.log("Bot [index.js] is ready!")
})

client.login(process.env.TOKEN)

我还有另一个文件,welcomeMessage:

const Discord = require("discord.js")
const client = new Discord.Client()

client.on("ready", () => {
    console.log("Bot [welcomeMessage.js] is ready!")
})

client.on('guildMemberAdd', member => {

    let welcomeChannel = client.channels.cache.get('0000000000000')

    welcomeChannel.send("hello world")
})

client.login(process.env.TOKEN)

是什么导致了这个问题?谢谢

【问题讨论】:

    标签: node.js heroku discord.js


    【解决方案1】:

    伙计,不知何故,我在这里做到了,第一次随机尝试对我有用,我很高兴!看,我希望它也对你有用。首先,去看看你的“package.json”文件,里面你必须有:

    "scripts": {
        
      },
    

    你应该把“start" : "node index.js”放在那里(即使'scripts'里面已经有其他东西了,但不要删除其他东西,只需添加这个)它将是这样的:

     "scripts": {
        "start": "node index.js",
      },
    

    然后转到您的 Procfile 并将“worker : node index.js”更改为“worker npm start”(我尝试过,因为我注意到只有 web 工作,它的命令是“web npm start”)

    应该能解决问题!

    我很确定这是为我解决的问题,现在它正在不停地运行,但如果它没有解决,我还在终端上使用了一些命令,命令:“heroku run worker”,还有“ heroku ps:scale worker=1"。

    我希望它会对你有所帮助,我连续 8 小时试图让它工作,因为我有其他错误,而且我知道这件事情不工作有多烦人。

    Obs.:你也需要按照别人之前说的去做:

    "(...) 你需要禁用 web dyno 并启用 worker dyno"。

    PS.:我知道你已经做了开始的事情,我只是想如果有人在没有这些信息的情况下到达这里也许会有所帮助。

    【讨论】:

      【解决方案2】:

      原来你需要禁用 web dyno 并启用 worker dyno。

      【讨论】:

        猜你喜欢
        • 2017-08-22
        • 2017-11-04
        • 1970-01-01
        • 1970-01-01
        • 2021-02-12
        • 2021-05-10
        • 2020-03-27
        • 1970-01-01
        • 2017-02-04
        相关资源
        最近更新 更多