node.js - VSCode 将调试附加到在 WSL 上运行的 nodejs
问题描述
我收到错误:无法连接到运行时进程,10000 毫秒后超时 - (原因:无法连接到目标)
NodeJs 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
launch.json 中的设置为正确的 WSL 路径。例如 my 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.js。目前 v8 是最新的 LTS 版本:Node.js 发布
推荐阅读
- reactjs - 为什么在带有反应的 axios 上发生错误 [ GET http://127.0.0.1:8000/api/user 401 (Unauthorized) ]
- flutter - 反向地理编码 Mapbox 结果
- python - 是否可以在 Python 中对标准输入进行两次连续、成功的非阻塞读取?
- signalr - SignalR 可以在客户端断开连接时对消息进行排队,并在客户端连接回来时将它们重新发送给客户端吗?
- spring - Spring Data JPA:管理和模拟可选记录
- python - 如何将文件复制到需要python访问权限的文件夹?
- flutter - Flutter:获取号码来电
- r - R中的频率和百分比表
- perl - 如何使用扩展名检查文件名并使用perl存储在数组中
- python - 为政府数据创建 Python 程序