Vscode: Unable to debug with integrated terminal (WSL)

Created on 25 May 2018  Â·  17Comments  Â·  Source: microsoft/vscode

  • VSCode Version: 1.23.1 & 1.24.0-insider
  • OS Version: Windows 10 - 1803

Steps to Reproduce:

  1. Create a node launch config
  2. Run with console set to "integratedTerminal"

This then launches a new integrated terminal, and executes the following:

➜ cd c:\Code\debug && node --inspect-brk=30756

Which in my case is invalid due to the initial cd c:\Code\debug, as I am using wsl:

cd: no such file or directory: c:Codedebug

I am aware of the previous issues involving this being closed as the problem was fixed, however this no longer seems to be the case.

Sample config:

    {
        "type": "node",
        "request": "launch",
        "name": "Launch Program",
        "console": "integratedTerminal",
    }
WSL bug debug verified

All 17 comments

Have you tried "useWSL": true?

Yes, this changes what is executed in the terminal to:

➜ cd c:\Code\debug && C:\WINDOWS\System32\bash.exe -ic "node --inspect-brk=48993"

So it attempts to run the node process using bash.exe, which shouldn't be necessary as it is doing that from within wsl to begin with, so just executing node should work.

Either way as far as I can tell this isn't really relevant as the first statement cd c:\Code\debug is unchanged, the part that executes node is never reached due to the use of \ instead of / in the cd statement.

Although the useWSL option actually also uses \, in addition to using an incorrect path to bash.exe.
The following executes node correctly:

mnt/c/Windows/System32/bash.exe -ic "node"

So it seems useWSL just compounds the issue.

It should make no difference to running bash.exe, but just in case my integrated terminal is running zsh via wsl.exe, with the following user setting:

"terminal.integrated.shell.windows": "C:\\Windows\\System32\\wsl.exe",

Which works as the backslashes are escaped unlike in the statements VSCode attempts to execute.

Ok, I guess it's assuming that your terminal is not already in WSL. @weinand do you know if this case should work?

As a workaround, what if you remove useWSL and set "cwd": "/path/to/project" so it doesn't take the windows-style path?

This doesn't seem to be allowed:

"Attribute 'cwd' is not absolute ('mnt/c/Code/debug'); consider adding '${workspaceFolder}/' as a prefix to make it absolute."

And when I run it with any variation of "cwd": "${workspaceFolder}" it just has the same output as previously.

I recently created a VS Code extension: WSL workspaceFolder, which may help.

Hi @lfurzewaddock, your extension works on mine. Thanks a lot!!

@adityawibisana What does your debug launch configuration look like in the end?

@adityawibisana What does your debug launch configuration look like in the end?

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

Borrowed shamelessly from @n0v1 in #54593

@ltomes and @virgilwashere : first I need the extension, and it is working. Turn out that it is working without extension too. Last config:

{
            "name": "WSL fix remoteRoot",
            "type": "node",
            "request": "attach",            
            "address": "localhost",
            "port": 5858,
            "sourceMaps": false,
            "localRoot": "${workspaceFolder}",
            "remoteRoot": "/mnt/d/Projects/yourAwesomeProject" 
}

On my case, most important part is the remoteRoot, which should point to your corresponding folder.

Do note that this one is attach, so you need to manually node debug app.js your project first

I'd like to add to @adityawibisana's comment:

[...] you need to manually npm start your project first

This makes the assumption that your package.json contains something like:

"scripts": {
    "start": "node --inspect-brk ./dist/index.js"
}

What's key is that your launch a node process with the --inspect/--inspect-brk set.

@rozzzly : No, my package.json:

"scripts": {
    "start": "node app.js",

edited: I did
node debug app.js, instead of npm start. And then, yap, pressing the play button on VS code

@adityawibisana

node debug app.js might work for you right now, per Node.js Foundation website

The legacy debugger has been deprecated as of Node 7.7.0. Please use --inspect and Inspector instead.
[...]
The V8 Debugging Protocol is no longer maintained or documented.

That was 2 years ago. Unless you have a _specific_ reason to use v7/the old protocol, using --inspect/--inspect-brk is advisable as they are two different mechanisms, not just an alias.

Also the port for --inspect/--inspect-brk defaults to 9229 not 5858 like the old debugger. If your launch config specifies that the port to be used is 5858, you'd need to specify that when spawning the process as well. --inspect=5858/--inspect-brk=5858

Hopefully that clears up any confusion for a visitor from google in a year or two. 😉

@rozzzly : 💯 That was using node v5, anyway :)

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

I'm having the same problem in the original post: cd: no such file or directory: c:Codedebug
It also uses 'bash.exe' instead of 'wsl.exe'.

However, it works if I don't use the option "console": "integratedTerminal".

I've installed the recent Remote WSL extension and it works in the WSL remote window, even with "console": "integratedTerminal". But not on a regular window.

This is my launch configuration:
{
"type": "node",
"request": "launch",
"name": "nodemon WSL",
"runtimeExecutable": "nodemon",
"program": "${workspaceFolder}/server.js",
"restart": true,
"protocol": "inspector",
"console": "integratedTerminal",
"internalConsoleOptions": "neverOpen",
"useWSL": true
}

@filetvignon the WSL extension is the solution to the problem, you cannot do it in a normal window by design.

Please remove the "useWSL": true option.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

DovydasNavickas picture DovydasNavickas  Â·  3Comments

trstringer picture trstringer  Â·  3Comments

mrkiley picture mrkiley  Â·  3Comments

VitorLuizC picture VitorLuizC  Â·  3Comments

curtw picture curtw  Â·  3Comments