I deployed my discord bot to Heroku but It is giving an error of unhandled promise rejection Here are the logs
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
CodePudding user response:
You would have to upgrade your node version. You may add the following to your package.json
:
"engines": {
"node": "16.9.1",
}
And redeploy your project and it would work
CodePudding user response:
Discord.js v13 needs AbortController
to function, but it was only introduced in node versions 16 and above. You have two options to fix this error:
Upgrade your node version on heroku to 16 or above
Use a polyfill for your AbortController ,
AbortController-polyfill
is a package to do that, you may utilise it like so:
const { AbortController } = require('abortcontroller-polyfill/dist/cjs-ponyfill');
global.AbortController = AbortController;