How to solve error “SyntaxError: Unexpected token ‘?'” uses node v12.22.1 but the nullish coalescing operator (??), is relatively new and was added in node v14.

So to use the ?? operator you need to update node in

Which you can do by following this forum post by lukenzy.

Create a file and name it .replit
Inside it, copy and paste the following code:

run = """
curl -o- |  bash
export NVM_DIR=\"$HOME/.nvm\"
[ -s \"$NVM_DIR/\" ] && \\. \"$NVM_DIR/\"
[ -s \"$NVM_DIR/bash_completion\" ] && \\.\"$NVM_DIR/bash_completion\"
nvm install 14
node index.js

This will install and use the latest Node.js v14 (14.17.4).
If u want to use a different version, change nvm install 14 to any other
Also, change node index.js to the file u want to run.

Leave a Comment