Daniesh Rieza
Daniesh Rieza

Reputation: 17

Incompatible code with node version on repl.it

As you can see, this is regarding discord.js bot. I've already upgrade node.js on repl.it into version 16 but even after I update it, when I click run, the following error still pops up on the console.

/home/runner/MathBot/node_modules/discord.js/src/rest/RESTManager.js:32 const token = this.client.token ?? this.client.accessToken;

How may I fix this?

Upvotes: 0

Views: 756

Answers (2)

iamkneel
iamkneel

Reputation: 1498

discord.js v13 only supports node versions of 16.6 and up. Head over to https://nodejs.org and grab the latest release.

Upvotes: 1

Zero
Zero

Reputation: 2286

The Nullish coalescing (??) operator is available only to node versions 14 and above which is on LTS as of now, although discord.js version 13 and above require node version 16 which is labelled as Current by npm and contains the latest features, the error simply indicates that your node version is below 14.

You may try the following methods:

Method 1:

• Create a bash repl which defaults to node version 14 and further install a dependency AbortController-Polyfill to fulfil the requirements of the features discord.js v13 needs to function

Define the AbortController globally like this: ​

const { AbortController } = require('abortcontroller-polyfill/dist/cjs-ponyfill');
global.AbortController = AbortController;  



Method 2
Step 1:
Add this to your package.json, ( this isn't malicious, it updates version to node 16 and forces to clean npm cache on replit so replit may not reject the process )

"scripts": {
  "start": "node .",
  "node-update": "npm i --save-dev node@16 && npm config set prefix=$(pwd)/node_modules/node && export PATH=$(pwd)/node_modules/node/bin:$PATH",
  "node-clean": "rm -rf node_modules && rm package-lock.json && npm cache clear --force && npm cache clean --force && npm i",
  "ez-v16": "npm run node-update && npm run node-clean-cache"
}

Step 2:
Run this in your shell `npm run ez-v16` and press the run button.

Upvotes: 2

Related Questions