Ask coding questions

← Back to all posts
Replit does not boot up
h
maxbrik

Hey There, When i press the run button it attempts to start but than it crashes after around 3 Seconds.

Hope Someone can help. (im using discord.js 13 with node.js 16)

Voters
maxbrik
Comments
hotnewtop
SixBeeps

Instead of running npm start, try running node bot.js instead.

maxbrik

okay let me try that (i tried but nope)
@SixBeeps

SixBeeps

@maxbrik It spits out an error, right?

maxbrik

@SixBeeps Yep when using node bot.js
The Error is:

 node bot.js
/home/runner/Tutorial-Bot/node_modules/discord.js/src/rest/RESTManager.js:32
const token = this.client.token ?? this.client.accessToken;
^

SyntaxError: Unexpected token '?'
at wrapSafe (internal/modules/cjs/loader.js:915:16)
at Module._compile (internal/modules/cjs/loader.js:963:27)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
at Module.load (internal/modules/cjs/loader.js:863:32)
at Function.Module._load (internal/modules/cjs/loader.js:708:14)
at Module.require (internal/modules/cjs/loader.js:887:19)
at require (internal/modules/cjs/helpers.js:74:18)
at Object.<anonymous> (/home/runner/Tutorial-Bot/node_modules/discord.js/src/client/BaseClient.js:4:21)
at Module._compile (internal/modules/cjs/loader.js:999:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1027:10)
exit status 1

SixBeeps

@maxbrik Yeah I noticed that's something that's been tripping people up recently. The nullish-coalescing operator was introduced to Node in v14.0, but Replit's Node Repl runs v12. The solution is to transfer your code to a Nix Repl, and import the pkgs.nodejs derivation.

Quick video showing you how to use Nix: https://www.youtube.com/watch?v=gItKAtedmq4

maxbrik

thanks a lot i appriate the help brb with the results @SixBeeps

maxbrik

that was how i installed node 16 @SixBeeps
Tips: Node v16 in Replit
1. Execute this script on the shell to install node and configure npm.
npm i --save-dev [email protected] && npm config set prefix=$(pwd)/node_modules/node && export PATH=$(pwd)/node_modules/node/bin:$PATH
And execute this to clean npm cache and reinstall the package.
rm -rf node_modules && rm package-lock.json && npm cache clear --force && npm cache clean --force && npm i

  1. Create the .replit to execute node from the shell instead of the console.
    run="npm start"

  2. Make sure to add the start script in your package.json file
    "scripts": {
    "start": "node ."
    }

You can also add all of it, in your package.json
"scripts": {
"start": "node .",
"node-update": "npm i --save-dev [email protected] && 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"
}

npm run node-update && npm run node-clean

  1. (Optional) If you had packages like canvas or sqlite before, you need to re-install those packages
    npm uninstall canvas && npm i canvas

Q: Is node version will reset after you leave in ur repl or the repl restarted?
A: No, when you check your node version in shell, it will still v12, but when you run your repl then console.log the process.version it will log the v16. So repl console is FAKE.

DiscordJS v13 requires node v16 or newer

SixBeeps

@maxbrik I mean yeah that works too. I just like the Nix solution because it requires less jank.

maxbrik

@SixBeeps So maybe making a new repl fixes it

maxbrik

@SixBeeps since i did that earlier already