Business
Jobs
  • About Us
  • Solutions
    • Job Postings
      Post your job and receive qualified candidates in 48h.
    • Candidate Assessments
      500+ technical and psychological tests, plus anti-fraud.
    • Headhunting
      Tailor-made executive search from start to finish.
    • Payroll + EOR
      Payroll dispersal and EOR across 15+ LATAM countries.
  • Pricing
  • Jobs

0

349
Views
Syntax error when using optional chaining (ES2020) in debug mode (VSCode) in node.js app

I get an "Uncaught SyntaxError: Unexpected token ." message when I try to use my express app in debug mode in VSCode (F5) if my code includes optional chaining (?.). I do not have this problem when I use the app with the command "npm start" which is working properly. I do not have experience on building projects with very specific configuration (compilers, lighters...), this one was created just with npm init.

Below you can see the details that I consider useful for solving the issue. Let me know if you need anything else. Is there anyway I can debug the app if it includes optional chaining syntax? Should I update any version? Should I change any config file?

Details:
node v16.10.0
npm v7.24.0

package.json

  "main": "server/server.js",
  "scripts": {
    "start": "nodemon -e js,json,html,yml,css server/server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  },
  "repository": {
    "type": "git",
  },
  "license": "ISC",
  "dependencies": {
    "@marsaud/smb2": "^0.17.2",
    "bcrypt": "^5.0.1",
    "body-parser": "^1.19.0",
    "compression": "^1.7.4",
    "cookie-parser": "^1.4.5",
    "cors": "^2.8.5",
    "equals": "^1.0.5",
    "express": "^4.17.1",
    "jsonwebtoken": "^8.5.1",
    "moment": "^2.24.0",
    "mongodb": "^3.6.5",
    "mssql": "^7.2.1",
    "nodemailer": "^6.4.10",
    "nodemon": "^2.0.7",
    "redoc": "^2.0.0-rc.24",
    "swagger-jsdoc": "^4.0.0",
    "tedious": "^14.0.0",
    "underscore": "^1.9.1"
  }
}

launch.json

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Iniciar el programa",

            "program": "${workspaceFolder}/backEnd/server/server.js"
          }
    ],
    
}
about 4 years ago · Santiago Trujillo
3 answers
Answer question

0

I had this same issue and downgrading npm to version 6.14.16 is what worked for me. Another work around that I was running while searching for a solution was to remove nodemon from the package.json scripts commands and replacing them with just node

"scripts": {
    "start": "node js,json,html,yml,css server/server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
},

and running

nodemon --exec npm run start

Not sure what the exact issue is though, but it seems to be related to running the nodemon command from within the scripts in package.json file. I was able to verify this by simply running

npm run start

with the package.json changes mentioned above perfectly fine, but once it was changed to run with nodemon, I run into issues with optional chaining.

about 4 years ago · Santiago Trujillo Report

0

I finally found the solution, I was not using the right debugger so it was mainly a Visual Studio Code wrong configuration setup issue. I recently installed some other debuggers so I had to set the node.js debugger again.

about 4 years ago · Santiago Trujillo Report

0

Did you try to switch to different node version? I use node v14 and don't have the problem, but I read on other websites mentioned that they are using v16 and also have problem with optional chaining.

about 4 years ago · Santiago Trujillo Report
Answer question
Find remote jobs

Discover the new way to find a job!

Top jobs
Top job categories
Business
Post vacancy Pricing Sales
Legal
Terms and conditions Privacy policy
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Show me some job opportunities
There's an error!