How to use optional chanining in Node v14?

I use node v14 and it has optional chaining but glitch doesn’t let me turn it on so please add it asap

Can you post a code example of it?

Here’s the screenshot of the code and the error


Ah, now I see what you mean! That is actually something typescript adopted from Rust, you’ll have to use TypeScript to be able to do that! (Except for Node v14 and higher)

How do I make it not error in node v14?

Wait you’re on Node14 and it still errors?

Yea it does error even when I’m in node v14

Are you running this on Glitch? On Node v14 you need to add the --harmony flag in order for it to be included into the runtime.

I’ve changed the title and put your post under Glitch Help category because:

  1. This was not a Glitch issue.
  2. This is already possibly with Node v14

I see, how do I use that --harmony flag?

In your package.json file you can append --harmony to the start script.

For instance:

  "name": "hello-express",
  "version": "0.0.1",
  "description": "A simple Node app built on Express, instantly up and running.",
  "main": "server.js",
  "scripts": {
    "start": "node server.js --harmony"
  "dependencies": {
    "express": "^4.17.1"
  "engines": {
    "node": "14.x"
  "repository": {
    "url": "!/hello-express"
1 Like

I get the same error still


Strange, I got it to work… Only thing that makes sense is that you aren’t using node v14

Well yea, I forgot that I put it back to v12 after it didn’t work to make the project online. Now I tried 14.x but it uses 10.x saying it can’t find v14

You can install nvm and run nvm install node.

But how do I even stop glitch from using v10. It’s using that only and not the nvm’s node version

You can try putting this in your start script: /app/.nvm/versions/node/v14.4.0/bin/node amazing.js --harmony

Still uses node v10 only

It’s because of that

"engines": {
    "node": "14.x"

Doesn’t make sense considering that Glitch doesn’t officially support 14.x?