Vscode: Not able to debug Node program using WSL

Created on 18 Jul 2018  ·  4Comments  ·  Source: microsoft/vscode


  • VSCode Version: 1.25.1
  • OS Version: Windows 10 Home 1803

I'm trying to debug a Node application using Windows Subsytem for Linux but I don't think the paths are translating.

This is my launch.json

{
  // Use IntelliSense to learn about possible attributes.
  // Hover to view descriptions of existing attributes.
  // For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
  "version": "0.2.0",
  "configurations": [
    {
      "type": "node",
      "request": "launch",
      "name": "Launch NestJS",
      "useWSL": true,
      "console": "integratedTerminal",
      "runtimeExecutable": "npm",
      "runtimeArgs": [
        "run-script",
        "start:dev"
      ],
      "port": 5000,
    }
  ]
}

and this is what appears in my console after attempting to debug:

isiah@isiah-acer:/mnt/c/Users/Isiah/Documents/Programming_Projects/etc/podcast_db/new-api$ cd "c:\Users\Isiah\Documents\Programming_Projects\etc\podcast_db\new-api" ; "C:\WINDOWS\System32\bash.exe" -ic "npm run-script start:dev"
-bash: cd: c:\Users\Isiah\Documents\Programming_Projects\etc\podcast_db\new-api: No such file or directory
C:\WINDOWS\System32\bash.exe: command not found

And for further information npm run-script start:dev runs nodemon and here is my nodemon.json:

{
  "watch": [
    "src"
  ],
  "ext": "ts",
  "ignore": [
    "src/**/*.spec.ts"
  ],
  "exec": "node -r tsconfig-paths/register --inspect=5000 --require ts-node/register src/main.ts"
}


Does this issue occur when all extensions are disabled?: Yes

WSL bug debug verified

Most helpful comment

I think this should work when removing "console": "integratedTerminal" from your launch configuration. "useWSL": true should be enough.

For debugging such a setup, I use the extension WSL workspaceFolder and add the following to my lauch configurations:

"localRoot": "${workspaceFolder}",
"remoteRoot": "${command:extension.vscode-wsl-workspaceFolder}",

Example that works for me:

{
  "type": "node",
  "request": "launch",
  "name": "Run NPM script in WSL",
  "useWSL": true,
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "${command:extension.vscode-wsl-workspaceFolder}",
  "runtimeExecutable": "npm",
  "runtimeArgs": [
    "run-script",
    "foo",
  ],
  "internalConsoleOptions": "openOnSessionStart",
  "skipFiles": [
    "<node_internals>/**/*.js",
  ],
},

To debug mocha tests, I use this launch configuration:

{
  "type": "node",
  "request": "launch",
  "name": "Run mocha tests in WSL",
  "useWSL": true,
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "${command:extension.vscode-wsl-workspaceFolder}",
  "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
  "args": [
    "-u",
    "tdd",
    "--timeout",
    "999999",
    "--colors",
    "--exit",
    "${command:extension.vscode-wsl-workspaceFolder}/tests/test.js"
  ],
  "internalConsoleOptions": "openOnSessionStart",
  "skipFiles": [
    "<node_internals>/**/*.js",
  ],
},

Note: output will be in "Debug Console" tab.

All 4 comments

This is a complex setup which is not yet supported.

I think this should work when removing "console": "integratedTerminal" from your launch configuration. "useWSL": true should be enough.

For debugging such a setup, I use the extension WSL workspaceFolder and add the following to my lauch configurations:

"localRoot": "${workspaceFolder}",
"remoteRoot": "${command:extension.vscode-wsl-workspaceFolder}",

Example that works for me:

{
  "type": "node",
  "request": "launch",
  "name": "Run NPM script in WSL",
  "useWSL": true,
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "${command:extension.vscode-wsl-workspaceFolder}",
  "runtimeExecutable": "npm",
  "runtimeArgs": [
    "run-script",
    "foo",
  ],
  "internalConsoleOptions": "openOnSessionStart",
  "skipFiles": [
    "<node_internals>/**/*.js",
  ],
},

To debug mocha tests, I use this launch configuration:

{
  "type": "node",
  "request": "launch",
  "name": "Run mocha tests in WSL",
  "useWSL": true,
  "localRoot": "${workspaceFolder}",
  "remoteRoot": "${command:extension.vscode-wsl-workspaceFolder}",
  "program": "${workspaceFolder}/node_modules/mocha/bin/_mocha",
  "args": [
    "-u",
    "tdd",
    "--timeout",
    "999999",
    "--colors",
    "--exit",
    "${command:extension.vscode-wsl-workspaceFolder}/tests/test.js"
  ],
  "internalConsoleOptions": "openOnSessionStart",
  "skipFiles": [
    "<node_internals>/**/*.js",
  ],
},

Note: output will be in "Debug Console" tab.

@n0v1 Worked for me. Thank you!

This is a common use case now with developing on WSL and having debugging working for me is critical for my work. Now to get python working 🤞

We just announced remote development with VS Code, check out the blog post for details https://code.visualstudio.com/blogs/2019/05/02/remote-development

Was this page helpful?
0 / 5 - 0 ratings