代码之家  ›  专栏  ›  技术社区  ›  Steve Lam

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

  •  0
  • Steve Lam  · 技术社区  · 7 年前

    无法连接到运行时进程,10000毫秒后超时-(原因:无法连接到目标)

    下面是我的启动.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 回复  |  直到 7 年前
        1
  •  0
  •   Leo Furze-Waddock    7 年前

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

    /vscode代码/启动.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.js releases

    推荐文章