我正在尝试在 heroku 上部署我的 node.js discord 机器人,但我不断收到错误

Posted

技术标签:

【中文标题】我正在尝试在 heroku 上部署我的 node.js discord 机器人,但我不断收到错误【英文标题】:I'm trying to deploy my node.js discord bot on heroku but I keep getting errors 【发布时间】:2021-11-30 20:32:53 【问题描述】:

我试图在 heroku 上部署我的 discord.js 机器人,但我总是收到错误并且机器人崩溃。我的代码很好,我在我的电脑上运行它,它没有给出任何错误。我按照此链接设置了我的 heroku 应用程序https://devcenter.heroku.com/articles/getting-started-with-nodejs#set-up。我完全按照它说的做了,但我收到了这个错误:

2021-10-12T08:15:45.604131+00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-12T08:15:46.708903+00:00 app[web.1]:
2021-10-12T08:15:46.709032+00:00 app[web.1]: > kurumi@1.0.0 start /app
2021-10-12T08:15:46.709036+00:00 app[web.1]: > node index.js
2021-10-12T08:15:46.709036+00:00 app[web.1]:
2021-10-12T08:15:46.772460+00:00 app[web.1]: /app/node_modules/discord.js/src/rest/APIRequest.js:33
2021-10-12T08:15:46.772464+00:00 app[web.1]: agent ??= new https.Agent( ...this.client.options.http.agent, keepAlive: true );
2021-10-12T08:15:46.772465+00:00 app[web.1]: ^^^
2021-10-12T08:15:46.772465+00:00 app[web.1]:
2021-10-12T08:15:46.772468+00:00 app[web.1]: SyntaxError: Unexpected token '??='
2021-10-12T08:15:46.772468+00:00 app[web.1]: at wrapSafe (internal/modules/cjs/loader.js:1001:16)
2021-10-12T08:15:46.772468+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1049:27)
2021-10-12T08:15:46.772471+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-12T08:15:46.772471+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-10-12T08:15:46.772471+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-10-12T08:15:46.772471+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-10-12T08:15:46.772472+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:93:18)
2021-10-12T08:15:46.772472+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/discord.js/src/rest/RESTManager.js:4:20)
2021-10-12T08:15:46.772472+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-10-12T08:15:46.772472+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-12T08:15:46.779715+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-10-12T08:15:46.779895+00:00 app[web.1]: npm ERR! errno 1
2021-10-12T08:15:46.783479+00:00 app[web.1]: npm ERR! kurumi@1.0.0 start: `node index.js`
2021-10-12T08:15:46.783529+00:00 app[web.1]: npm ERR! Exit status 1
2021-10-12T08:15:46.783595+00:00 app[web.1]: npm ERR!
2021-10-12T08:15:46.783640+00:00 app[web.1]: npm ERR! Failed at the kurumi@1.0.0 start script.
2021-10-12T08:15:46.783698+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-10-12T08:15:46.786955+00:00 app[web.1]:
2021-10-12T08:15:46.787031+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-12T08:15:46.787064+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-10-12T08_15_46_784Z-debug.log
2021-10-12T08:15:46.938086+00:00 heroku[web.1]: Process exited with status 1
2021-10-12T08:15:47.109411+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-12T08:15:47.120433+00:00 heroku[web.1]: State changed from crashed to starting
2021-10-12T08:15:50.000000+00:00 app[api]: Build succeeded
2021-10-12T08:15:51.902833+00:00 heroku[web.1]: Starting process with command `npm start`
2021-10-12T08:15:52.879739+00:00 app[web.1]:
2021-10-12T08:15:52.879754+00:00 app[web.1]: > kurumi@1.0.0 start /app
2021-10-12T08:15:52.879755+00:00 app[web.1]: > node index.js
2021-10-12T08:15:52.879755+00:00 app[web.1]:
2021-10-12T08:15:52.943619+00:00 app[web.1]: /app/node_modules/discord.js/src/rest/APIRequest.js:33
2021-10-12T08:15:52.943621+00:00 app[web.1]: agent ??= new https.Agent( ...this.client.options.http.agent, keepAlive: true );
2021-10-12T08:15:52.943621+00:00 app[web.1]: ^^^
2021-10-12T08:15:52.943622+00:00 app[web.1]:
2021-10-12T08:15:52.943622+00:00 app[web.1]: SyntaxError: Unexpected token '??='
2021-10-12T08:15:52.943623+00:00 app[web.1]: at wrapSafe (internal/modules/cjs/loader.js:1001:16)
2021-10-12T08:15:52.943623+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1049:27)
2021-10-12T08:15:52.943624+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-12T08:15:52.943624+00:00 app[web.1]: at Module.load (internal/modules/cjs/loader.js:950:32)
2021-10-12T08:15:52.943624+00:00 app[web.1]: at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-10-12T08:15:52.943625+00:00 app[web.1]: at Module.require (internal/modules/cjs/loader.js:974:19)
2021-10-12T08:15:52.943625+00:00 app[web.1]: at require (internal/modules/cjs/helpers.js:93:18)
2021-10-12T08:15:52.943625+00:00 app[web.1]: at Object.<anonymous> (/app/node_modules/discord.js/src/rest/RESTManager.js:4:20)
2021-10-12T08:15:52.943627+00:00 app[web.1]: at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-10-12T08:15:52.943627+00:00 app[web.1]: at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-10-12T08:15:52.950345+00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-10-12T08:15:52.950523+00:00 app[web.1]: npm ERR! errno 1
2021-10-12T08:15:52.953970+00:00 app[web.1]: npm ERR! kurumi@1.0.0 start: `node index.js`
2021-10-12T08:15:52.954012+00:00 app[web.1]: npm ERR! Exit status 1
2021-10-12T08:15:52.954061+00:00 app[web.1]: npm ERR!
2021-10-12T08:15:52.954092+00:00 app[web.1]: npm ERR! Failed at the kurumi@1.0.0 start script.
2021-10-12T08:15:52.954134+00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-10-12T08:15:52.956414+00:00 app[web.1]:
2021-10-12T08:15:52.956490+00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-10-12T08:15:52.956517+00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-10-12T08_15_52_954Z-debug.log
2021-10-12T08:15:53.132196+00:00 heroku[web.1]: Process exited with status 1
2021-10-12T08:15:53.198551+00:00 heroku[web.1]: State changed from starting to crashed
2021-10-12T08:16:14.979868+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/" host=gentle-thicket-97709.herokuapp.com request_id=bc0fd458-0a88-4f7f-8fe6-7a21d52e3035 fwd="114.31.4.178" dyno= connect= service= status=503 bytes= protocol=https
2021-10-12T08:16:15.988690+00:00 heroku[router]: at=error code=H10 desc="App crashed" method=GET path="/favicon.ico" host=gentle-thicket-97709.herokuapp.com request_id=b830f6e2-5525-4310-b415-4e902015b8e3 fwd="114.31.4.178" dyno= connect= service= status=503 bytes= protocol=https

【问题讨论】:

这能回答你的问题吗? Discord bot on Heroku throws an error: agent ??= new https.Agent 【参考方案1】:

Heroku 的 nodejs 版本非常低,遗憾的是您无法更新它,因此没有真正的方法可以修复它。如果它适用于 djs v12.5.3,你仍然可以在这里运行一个机器人

【讨论】:

哦.. 很快会有更新吗? 我不知道,对不起。我不是网站工作人员【参考方案2】:

您可以在使用 heroku 时使用 engines 属性在 package.json 中指定节点版本。您可以尝试将版本设置为15 或更高版本吗?


  "name": "myapp",
  "description": "a really cool app",
  "version": "1.0.0",
  "engines": 
    "node": "15.x"
  

【讨论】:

以上是关于我正在尝试在 heroku 上部署我的 node.js discord 机器人,但我不断收到错误的主要内容,如果未能解决你的问题,请参考以下文章

将 Node.js 应用程序部署到 Heroku 的应用程序错误

在 Heroku 上部署 node.js 应用程序(discord.jd bot)导致错误

Node.js/ Ionic 应用程序未在 Heroku 上正确部署

Node.js 应用程序在本地主机上运行良好,但在 Heroku 上部署时显示错误

通过 Heroku 部署 Rails 应用程序使用旧版本的 Node

在heroku上使用vue应用程序部署rails 6时出现node-gyp错误