Home > Software engineering >  SyntaxError: Unexpected token '??=' when hosting a Discord bot on heroku
SyntaxError: Unexpected token '??=' when hosting a Discord bot on heroku

Time:11-05

i wanted to host a discord bot that i created (with Node.js) on Heroku but is throwing that error:

2021-11-05T00:00:10.334347 00:00 app[web.1]: > node .
2021-11-05T00:00:10.334348 00:00 app[web.1]: 
2021-11-05T00:00:10.393407 00:00 app[web.1]: /app/node_modules/discord.js/src/rest/APIRequest.js:33
2021-11-05T00:00:10.393408 00:00 app[web.1]:     agent ??= new https.Agent({ ...this.client.options.http.agent, keepAlive: true });
2021-11-05T00:00:10.393409 00:00 app[web.1]:           ^^^
2021-11-05T00:00:10.393409 00:00 app[web.1]: 
2021-11-05T00:00:10.393409 00:00 app[web.1]: SyntaxError: Unexpected token '??='
2021-11-05T00:00:10.393412 00:00 app[web.1]:     at wrapSafe (internal/modules/cjs/loader.js:1001:16)
2021-11-05T00:00:10.393413 00:00 app[web.1]:     at Module._compile (internal/modules/cjs/loader.js:1049:27)
2021-11-05T00:00:10.393413 00:00 app[web.1]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-11-05T00:00:10.393413 00:00 app[web.1]:     at Module.load (internal/modules/cjs/loader.js:950:32)
2021-11-05T00:00:10.393414 00:00 app[web.1]:     at Function.Module._load (internal/modules/cjs/loader.js:790:12)
2021-11-05T00:00:10.393414 00:00 app[web.1]:     at Module.require (internal/modules/cjs/loader.js:974:19)
2021-11-05T00:00:10.393414 00:00 app[web.1]:     at require (internal/modules/cjs/helpers.js:93:18)
2021-11-05T00:00:10.393415 00:00 app[web.1]:     at Object.<anonymous> (/app/node_modules/discord.js/src/rest/RESTManager.js:4:20)
2021-11-05T00:00:10.393415 00:00 app[web.1]:     at Module._compile (internal/modules/cjs/loader.js:1085:14)
2021-11-05T00:00:10.393415 00:00 app[web.1]:     at Object.Module._extensions..js (internal/modules/cjs/loader.js:1114:10)
2021-11-05T00:00:10.400407 00:00 app[web.1]: npm ERR! code ELIFECYCLE
2021-11-05T00:00:10.400581 00:00 app[web.1]: npm ERR! errno 1
2021-11-05T00:00:10.403958 00:00 app[web.1]: npm ERR! discord-bot@1.0.0 start: `node .`
2021-11-05T00:00:10.403998 00:00 app[web.1]: npm ERR! Exit status 1
2021-11-05T00:00:10.404053 00:00 app[web.1]: npm ERR! 
2021-11-05T00:00:10.404092 00:00 app[web.1]: npm ERR! Failed at the discord-bot@1.0.0 start script.
2021-11-05T00:00:10.404140 00:00 app[web.1]: npm ERR! This is probably not a problem with npm. There is likely additional logging output above.
2021-11-05T00:00:10.408367 00:00 app[web.1]: 
2021-11-05T00:00:10.408447 00:00 app[web.1]: npm ERR! A complete log of this run can be found in:
2021-11-05T00:00:10.408486 00:00 app[web.1]: npm ERR!     /app/.npm/_logs/2021-11-05T00_00_10_404Z-debug.log
2021-11-05T00:00:10.592782 00:00 heroku[web.1]: Process exited with status 1
2021-11-05T00:00:10.917668 00:00 heroku[web.1]: State changed from starting to crashed

this is my package.json:

  "name": "discord-bot",
  "version": "1.0.0",
  "description": "",
  "main": "src/index.js",
  "scripts": {
    "start": "node .",
    "test": "echo \"Error: no test specified\" && exit 1",
    "dev": "nodemon src/index.js"
  },
  "keywords": [],
  "author": "",
  "license": "ISC",
  "dependencies": {
    "cli": "^1.0.1",
    "discord.js": "^13.3.1",
    "discord.js-commando": "^0.12.3"
  },
  "devDependencies": {
    "nodemon": "^2.0.14"
  }
} 

i added a procfile too : worker: node src/index.js

i have the Node.js latest version (16.0)

what should i do to fix that error?

CodePudding user response:

Update node to >= v16.6.0.

https://github.com/discordjs/discord.js/issues/5119

CodePudding user response:

i just update discord.js to version 12.5.3 and worked! i appreciate all the answers

CodePudding user response:

For me that looks like you don't passed a token.

If you getting the token out of an file, please make sure it gets readed correctly.

  • Related