Vscode: 无法使用WSL调试Node程序

创建于 2018-07-18  ·  4评论  ·  资料来源: microsoft/vscode


  • VSCode版本:1.25.1
  • 作业系统版本:Windows 10 Home 1803

我正在尝试使用Windows Subsytem for Linux调试Node应用程序,但是我不认为路径正在翻译。

这是我的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,
    }
  ]
}

这是尝试调试后在控制台中显示的内容:

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

有关更多信息, npm run-script start:dev运行nodemon ,这是我的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"
}


禁用所有扩展后是否会发生此问题?:是

WSL bug debug verified

最有用的评论

我认为从启动配置中删除"console": "integratedTerminal"时,这应该可以工作。 "useWSL": true应该足够了。

为了调试这样的设置,我使用扩展名WSLworkspaceFolder并将以下内容添加到我的lauch配置中:

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

对我有用的示例:

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

要调试摩卡测试,我使用以下启动配置:

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

注意:输出将在“调试控制台”选项卡中。

所有4条评论

这是一个尚不支持的复杂设置。

我认为从启动配置中删除"console": "integratedTerminal"时,这应该可以工作。 "useWSL": true应该足够了。

为了调试这样的设置,我使用扩展名WSLworkspaceFolder并将以下内容添加到我的lauch配置中:

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

对我有用的示例:

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

要调试摩卡测试,我使用以下启动配置:

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

注意:输出将在“调试控制台”选项卡中。

@ n0v1为我工作。 谢谢!

现在,这是在WSL上进行开发的常见用例,调试对我来说至关重要。 现在让python工作working

我们刚刚宣布使用VS Code进行远程开发,请查看博客文章以了解详细信息https://code.visualstudio.com/blogs/2019/05/02/remote-development

此页面是否有帮助?
0 / 5 - 0 等级