javascriptnode.jsvisual-studio-codevscode-debuggerecmascript-2020

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"
          }
    ],
    
}

Solution

  • 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.