Why am I getting a ReferenceError: AbortController is not defined in Discord.js v13?
The Issue:
One of the prerequisites for using Discord.js v13 is that you need to use NodeJS v16.6 or higher (emphasis mine):
v13 requires Node 16.6 or higher to use, so make sure you're up to
date. To check your Node version, use node -v
The Fix:
The fix is to update your node version, you can confirm your current node version by running node -v
. There are a variety of different ways to update node, one way is to run the following commands if you're using Linux / iOS:
> npm install -g n
> n latest
The first command installs the command-line interface n, and then the second uses n
to update to the latest stable version of node. If you're on Windows, you can install NVM as outlined in this answer by pradeek.
Note for Heroku users:
Once you have followed the above steps to update your node version, you might then be required to update your package.json
file by adding/updating the engines:
"engines": {
"node": "16.x"
}
Why this broke in v13?:
A few versions ago of discordjs, a feature was added that aborts requests that take too long (longer than 15 seconds). In order to achieve this functionality, they were previously using the node package abort-controller. However, now that nodejs has evolved, it now has its own AbortController global without the need to require an external package. Discord.js v13 now relies on this global as they're no longer using the abort controller package. In order to use the AbortController
global provided by nodejs, you need to be using node v15 or higher - however, as recommended by the discord.js guide, you should be using v16.6+ to enable support for other features it may use.
Discord bot UnhandledPromiseRejectionWarning in production ( HEROKU)
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
Discord bot not starting with heroku
I recently came across this error too.
Discord.js version 13 runs on node 16.6.1, however, the default Heroku node version is 14.x.
That means we have to specify the version that we want Heroku to build our app on.
In package.json add
"engines": {
"node": "16.x",
"npm": "7.x"
}
Reference: https://devcenter.heroku.com/articles/nodejs-support#specifying-a-node-js-version
This specifies to the buildpack that we need to use the latest version of node 16 and npm 7.
However, after I added that, I came across a deployment error, and referred to this stack overflow question
The answer there stated to add an empty ".npmignore" file in your root folder, and so I did that. However, after pushing everything to Github, I still received the same deployment error.
It was saying that the file "node.exe" in a temp directory was missing.
After some trial and error, I decided to commit and push the "node_modules/" directory to the Github (that took some time), because (sorry I didn't copy the build logs) the file "node.exe" resided in the "node_modules/" directory, and then re-deployed my application, and it worked!
All in all it was kind of a roundhouse trip, because I don't know if the ".npmignore" file does anything (please comment if I'm wrong!).
To recap what I did to fix my application:
- Add the engine specifiers to package.json
- Add .npmignore to the root directory (up to you if you want to add it)
- Commit and push the node modules folder to the Github page as well.
- Deploy through Github
FYI: I don't know if this works on Heroku Git... tell me in the comments if it works.
Discord.JS bot on heroku
Your questions was already answered in another question. Answer by Nick Parsons. Basically, you have to change your node version.
Related Topics
New Es6 Syntax for Importing Commonjs/Amd Modules I.E. 'Import Foo = Require('Foo')'
Differencebetween JavaScript Promises and Async Await
Make Browser Window Blink in Task Bar
How to Extend Function with Es6 Classes
How to Prevent Form from Submitting Multiple Times from Client Side
Understanding Prototypal Inheritance in JavaScript
What Does the @ Mean Inside an Import Path
Three.Js Generate Uv Coordinate
Chrome, JavaScript, Window.Open in New Tab
JSON.Stringify Doesn't Work with Normal JavaScript Array
How to Destructure Object Properties with Key Names That Are Invalid Variable Names
Adding Custom Functions into Array.Prototype
Filtering Array of Objects with Arrays Based on Nested Value
Get First and Last Date of Current Month with JavaScript or Jquery
How to Capitalize First Letter of Each Word, Like a 2-Word City