VSCode将调试附加到在WSL上运行的nodejs

时间:2018-10-04 06:29:11

标签: node.js visual-studio-code

我收到错误消息: 无法连接到运行时进程,10000ms后超时-(原因:无法连接到目标)

NodeJ v4.3.1在WSL上运行。

以下是我的launch.json

"type": "node",
"request": "attach",
"name": "Attach to WSL",
"port": 3000,
"address": "localhost",
"restart": true,
"protocol": "inspector",
"localRoot": "${workspaceFolder}/web-frontend",
"remoteRoot": "/mnt/c/workspace/.../web-frontend"

WSL使用Windows的路径,因此localRoot和remoteRoot相同。

到目前为止我还缺少什么?

1 个答案:

答案 0 :(得分:0)

我创建了一个VS代码扩展名:WSL workspaceFolder,它将帮助您将launch.json中的remoteRoot自动设置为正确的WSL路径。例如,根据您的文件路径,我的launch.json如下所示;

/vscode/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": "attach", "name": "Attach to Remote", "address": "localhost", "port": 5858, "localRoot": "${workspaceFolder}/web-frontend", "remoteRoot": "${command:extension.vscode-wsl-workspaceFolder}/web-frontend" } ] }

然后启动调试会话,请在WSL终端中输入您要调试的脚本的路径之前的NODE_ENV=debug node --nolazy --inspect-brk=5858

但是,使用Node v4可能会遇到问题,因为它不支持“检查器协议”。我强烈建议您升级到最新版本的Node。当前,v8是最新的LTS版本:Node.js releases

相关问题