Use optional chaining operatori in Nodejs 14.x

Viewed 1311

i try to use optional chaining operator in Nodejs, i have window 10 with nvm installed. I have try use my script with node 14.5 and 15 but the response it's always the same

C:\Users\user1\AppData\Roaming\nvm\v15.6.0\node64.exe C:\Users\user1\AppData\Roaming\nvm\v15.6.0\node_modules\npm\bin\npm-cli.js run exec-list --scripts-prepend-node-path=auto

> oracle-node-service@1.0.0 exec-list   
> node src/exec.js list json=myfile.json

C:\xampp\htdocs\oracle-node-service\src\exec.js:388
    ...setup.templates.handlebars?.filters?.FILTERS[0].COLUMNS_UNIQUE,      
                                  ^

SyntaxError: Unexpected token .

this is started by phpstorm, i have tryed add this annotation in package.json but not work

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

PACKACGE JSON

{
  "name": "oracle-node-service",
  "version": "1.0.0",
  "main": "index.js",
  "scripts": {
    "build": "babel ./src --out-dir ./build",
    "start": "node src/index.js",
    "start-dev": "nodemon --exec babel-node src/index.js",
    "lint": "eslint .",
    "test": "echo \"Error: no test specified\" && exit 1",
    "exec": "node src/exec.js list detail filters json=myfile.json",
    "exec-list": "node src/exec.js list json=myfile.json",
    "exec-detail": "node src/exec.js detail json=myfile.json",
    "exec-filters": "node src/exec.js list detail filters json=configuration-filters.json",
    "exec-list-detail": "node src/exec.js list detail json=configuration-list-detail.json",
    "exec-filters-list-detail": "node src/exec.js filters list detail json=configuration-filters-list-detail.json"
  },
  "license": "ISC",
  "devDependencies": {
    "@babel/cli": "^7.14.5",
    "@babel/core": "^7.14.6",
    "@babel/node": "^7.14.5",
    "@babel/preset-env": "^7.14.5",
    "@babel/runtime": "^7.14.6",
    "eslint": "^7.29.0",
    "eslint-config-airbnb-base": "^14.2.1",
    "eslint-config-prettier": "^8.3.0",
    "eslint-plugin-import": "^2.23.4",
    "eslint-plugin-prettier": "^3.4.0",
    "nodemon": "^2.0.7"
  },
  "dependencies": {
    "handlebars": "^4.7.7",
    "moment": "^2.29.1",
    "oracledb": "^5.2.0",
    "prompt-sync": "^4.2.0",
    "lodash": "^4.17.21"
  },
  "engines": {
    "node": "14.x"
  }
}
1 Answers

Engines in package.json specify what version of Node.js should be supported. See docs. Optional chaining supported from Node.js version 14. Try to check what node version you have currently.

node -v
Related