0

I want to use debug in Visual Studio Code, but as my code full of const declarations, I can't run it - I'm getting an error:

Block-scoped declarations (let, const, function, class) not yet supported outside strict mode

Is any workaround existed, configuration file setting or something? Currently, my configuration file looks like this:

"version": "0.2.0",
"configurations": [
    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "program": "${workspaceRoot}/server.js"
    }
]

I've seen posts about 'use strict' line, but I was wandering if there is another solution, except putting that statements in all the files

Vladyslav Zavalykhatko
  • 15,202
  • 8
  • 65
  • 100
  • 2
    Possible duplicate of [Uncaught SyntaxError: Block-scoped declarations (let, const, function, class) not yet supported outside strict mode](https://stackoverflow.com/questions/33001246/uncaught-syntaxerror-block-scoped-declarations-let-const-function-class-no) – GSerg Aug 12 '17 at 18:26
  • What version of `node` do you have installed? All still supported versions of Node (i.e., 4.0.0 or newer) should support ES6 `let` and `const` statements outside of strict mode. I therefore suspect you have an old and out-of-support version of Node, and if possible I'd recommend to upgrade. – Frxstrem Aug 12 '17 at 18:34
  • Are you seeing this when running with vscode, but not when running manually? All vscode does is invoke `node` on your path. So it may be that vscode is finding a different version of node. Otherwise, how are you running your program, besides running it in vscode? – Rob Lourens Aug 13 '17 at 06:41
  • @RobLourens, as you can see from my configuration, I only set path to my server.js file. on the opposite, in my package.json start looks like this: "start": "nodemon --exec babel-node server.js --ignore public/". maybe babel-node is the reason I can run npm start without strict mode? I'm not sure :) – Vladyslav Zavalykhatko Aug 13 '17 at 07:23

1 Answers1

1

You say above that you normally start the app from an npm script: "start": "nodemon --exec babel-node server.js --ignore public/". Babel is transpiling your code and probably inserting "use strict". To debug this in vscode, you should invoke the same command.

There are a few ways to set it up, one would be to follow the example here: https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_launch-configuration-support-for-npm-and-other-tools, to add the debug arg to your npm script, then point the launch config at the npm script.

Rob Lourens
  • 15,081
  • 5
  • 76
  • 91