Home > Back-end >  Discord.js Heroku error: Unexpected token ??=
Discord.js Heroku error: Unexpected token ??=

Time:12-17

I'm currently working on a Discord bot and i want to deploy a hosting named Heroku.

But if i want to try deploy to Heroku, Its return an error. This is the error:

2021-12-14T16:25:08.161176 00:00 app[web.1]: > [email protected] start /app
2021-12-14T16:25:08.161176 00:00 app[web.1]: > node index.js
2021-12-14T16:25:08.161177 00:00 app[web.1]: 
2021-12-14T16:25:08.207168 00:00 app[web.1]: /app/node_modules/discord.js/src/rest/APIRequest.js:33
2021-12-14T16:25:08.207170 00:00 app[web.1]:     agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
2021-12-14T16:25:08.207170 00:00 app[web.1]:           ^^^
2021-12-14T16:25:08.207171 00:00 app[web.1]: 
2021-12-14T16:25:08.207171 00:00 app[web.1]: SyntaxError: Unexpected token '??='
2021-12-14T16:25:08.207171 00:00 app[web.1]:     at wrapSafe (internal/modules/cjs/loader.js:1001:16)
2021-12-14T16:25:08.207172 00:00 app[web.1]:     at Module._compile (internal/modules/cjs/loader.js:1049:27)
2021-12-14T16:25:08.207172 00:00 app[web.1]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-12-14T16:25:08.207172 00:00 app[web.1]:     at Module.load (internal/modules/cjs/loader.js:950:32)
2021-12-14T16:25:08.207173 00:00 app[web.1]:     at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-12-14T16:25:08.207173 00:00 app[web.1]:     at Module.require (internal/modules/cjs/loader.js:974:19)
2021-12-14T16:25:08.207173 00:00 app[web.1]:     at require (internal/modules/cjs/helpers.js:93:18)
2021-12-14T16:25:08.207173 00:00 app[web.1]:     at Object.<anonymous> (/app/node_modules/discord.js/src/rest/RESTManager.js:4:20)
2021-12-14T16:25:08.207174 00:00 app[web.1]:     at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-12-14T16:25:08.207174 00:00 app[web.1]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)

Thanks for answering my question!

CodePudding user response:

In the package.json, please place this into the package.json:

"engines": {
  "node": "16.x",
  "npm": "7.x"
},

Full:

{
  "name": "your bot name",
  "version": "1.0.0",
  "description": "your bot description",
  "main": "index.js",
  "engines": {
    "node": "16.x",
    "npm": "7.x"
  },
  "scripts": {
    "start": "node ."
  },
  "author": "your name",
  "license": "MIT",
  "dependencies": {
    "discord.js": "^13.1.0"
  }
}

Credit: Thanks to @Zsolt Meszaros for the answer.

  • Related