繁体   English   中英

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

[英]VSCode attach debug to nodejs which run on WSL

我收到错误消息:无法连接到运行时进程,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相同。

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

我创建了一个VS Code扩展名: WSL WorkspaceFolder ,它将帮助您自动将remoteRoot中的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版本

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM