software_writer
software_writer

Reputation: 4478

VS Code debug with --experimental-modules flag

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

Upvotes: 6

Views: 4005

Answers (2)

KyleMit
KyleMit

Reputation: 30227

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

Upvotes: 5

benspaulding
benspaulding

Reputation: 323

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.

Upvotes: 11

Related Questions