6

I can run my node.js application with es6 modules with the --experimental-modules flag as follows:

node --experimental-modules ./bin/www

How can I do the same when debuggging the application from VS Code, which uses the launch.json configuration file?

{
    "version": "0.2.0",
    "configurations": [
        {
          "type": "node",
          "request": "launch",
          "name": "Launch Program",
          "program": "${workspaceFolder}\\bin\\www",
        }
    ]
}
software_writer
  • 3,941
  • 9
  • 38
  • 64

2 Answers2

10

Instead of using the "program" key you can pass the needed flag in "args" before you pass it your module.

node --experimental-modules ./myModule
{
  "version": "0.2.0",
  "configurations": [
    {
      "name": "run module",
      "type": "node",
      "request": "launch",
      "args": ["--experimental-modules", "${workspaceFolder}/myModule"]
    }
  ]
}

I only learned this last week trying to do the same thing with a Python program.

benspaulding
  • 313
  • 1
  • 6
  • 1
    Nice one. In a few months, future-me will be very confused trying figure out how this config works, but that's his problem. – Stewii Apr 29 '20 at 02:10
3

The official guidance is to use the runtimeArgs attribute like this:

{
    "name": "Launch Program",
    "request": "launch",
    "type": "node",
    "runtimeArgs": ["--experimental-modules"],
    "program": "${workspaceFolder}\\bin\\www"
}

Which will run the following terminal command:

node.exe --experimental-modules .\bin\www

See Also: How to start nodejs with custom params from vscode

KyleMit
  • 30,350
  • 66
  • 462
  • 664