Glitch editor flags optional chaining

Whenever i’ve tried to use the chaining method in an express app it doesnt recognize it

  ?.map((user) => [user.player.name, user.player.gold])
   ^
SyntaxError: Unexpected token .
    at Module._compile (internal/modules/cjs/loader.js:723:23)
    at Object.Module._extensions..js (internal/modules/cjs/loader.js:789:10)

Maybe there’s a config file which I need to edit? Or maybe this isn’t allowed? Not sure, any guidance would be appreciated!

Optional chaining is only supported in node versions >=14.0.0, so you’ll need to set the engines.node field in your package.json to an appropriate version number (either 14.x or 16.x):

"engines": {
    "node": "16.x"
}
2 Likes