【问题标题】:Discord bot UnhandledPromiseRejectionWarning in production ( HEROKU) [duplicate]Discord bot UnhandledPromiseRejectionWarning 在生产中(HEROKU)[重复]
【发布时间】:2021-11-07 06:49:14
【问题描述】:

我将我的不和谐机器人部署到 Heroku,但它给出了未处理的承诺拒绝错误 这是日志

2021-09-10T20:50:26.000000+00:00 app[api]: Build started by user codertanishq@gmail.com
2021-09-10T20:50:45.558185+00:00 app[api]: Deploy c608c194 by user codertanishq@gmail.com
2021-09-10T20:50:45.558185+00:00 app[api]: Release v11 created by user codertanishq@gmail.com
2021-09-10T20:50:46.000000+00:00 app[api]: Build succeeded
2021-09-10T20:50:46.978335+00:00 heroku[web.1]: State changed from crashed to starting
2021-09-10T20:50:48.877754+00:00 heroku[web.1]: Starting process with command `npm start`
2021-09-10T20:50:51.529490+00:00 app[web.1]: 
2021-09-10T20:50:51.529505+00:00 app[web.1]: > start@1.0.0 start /app
2021-09-10T20:50:51.529506+00:00 app[web.1]: > node ./src/bot.js
2021-09-10T20:50:51.529506+00:00 app[web.1]: 
2021-09-10T20:50:51.762757+00:00 app[web.1]: (node:22) UnhandledPromiseRejectionWarning: ReferenceError: AbortController is not defined
2021-09-10T20:50:51.762758+00:00 app[web.1]:     at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:172:15)
2021-09-10T20:50:51.762758+00:00 app[web.1]:     at RequestHandler.execute (/app/node_modules/discord.js/src/rest/RequestHandler.js:176:19)
2021-09-10T20:50:51.762758+00:00 app[web.1]:     at RequestHandler.push (/app/node_modules/discord.js/src/rest/RequestHandler.js:50:25)
2021-09-10T20:50:51.762759+00:00 app[web.1]:     at async WebSocketManager.connect (/app/node_modules/discord.js/src/client/websocket/WebSocketManager.js:128:9)
2021-09-10T20:50:51.762759+00:00 app[web.1]:     at async Client.login (/app/node_modules/discord.js/src/client/Client.js:245:7)
2021-09-10T20:50:51.762759+00:00 app[web.1]: (Use `node --trace-warnings ...` to show where the warning was created)
2021-09-10T20:50:51.763064+00:00 app[web.1]: (node:22) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
2021-09-10T20:50:51.763091+00:00 app[web.1]: (node:22) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
2021-09-10T20:50:51.847328+00:00 heroku[web.1]: Process exited with status 0
2021-09-10T20:50:51.902780+00:00 heroku[web.1]: State changed from starting to crashed

【问题讨论】:

  • 将heroku上的节点更新到16.6.0

标签: node.js heroku discord.js


【解决方案1】:

您必须升级您的节点版本。您可以将以下内容添加到您的package.json

"engines": {
    "node": "16.9.1",
  }

然后重新部署你的项目,它会工作

【讨论】:

    【解决方案2】:

    Discord.js v13 需要AbortController 才能运行,但它仅在节点版本 16 及更高版本中引入。您有两种方法可以修复此错误:

    • 将heroku上的节点版本升级到16或以上

    • 为你的 AbortController 使用 polyfill,AbortController-polyfill 是一个包,你可以像这样使用它:

    const { AbortController } = require('abortcontroller-polyfill/dist/cjs-ponyfill');
    global.AbortController = AbortController;
    

    【讨论】:

      猜你喜欢
      • 2021-03-30
      • 2021-01-11
      • 1970-01-01
      • 2019-04-26
      • 2021-10-14
      • 2021-11-11
      • 2020-12-21
      • 2020-09-27
      • 2021-05-13
      相关资源
      最近更新 更多