Discord bot on Heroku throws an error: agent ??= new https.Agent

The error is coming from discord.js and it’s because you’re using an older version of Node.js. The logical nullish assignment operator (??=) is only available in node v15+.

You might think that you’re using the latest version of Node.js, but Heroku says that “if a Node version isn’t specified in the engine, the 14.x release will be used”. You can add an engines prop to your package.json file to specify the version you need. As discord.js v13 requires node.js v16.6+, you can add the following:

  "engines": {
    "node": "16.6"
  }

Or to request the latest v16, add this:

  "engines": {
    "node": "16.x"
  }

Leave a Comment