Error: Cannot connect to runtime; make sure that runtime is in 'legacy' debug mode

Error: Cannot connect to runtime; make sure that runtime is in 'legacy' debug mode

我在尝试使用 Visual Studio 代码调试 Node.js 脚本时看到上面的内容。

我的launch.json长得像

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "attach",
            "name": "Attach to Process",
            "protocol": "legacy",
            "processId": "${command:PickProcess}"
        }
    ]
}

无论我是否输入 "protocol": "legacy", 行,我都会得到与上面完全相同的错误。 我的环境 系统:OSX 节点:v8.6.0 VSC:1.17.2 另外,我 运行 带有 PM2 的节点脚本。

任何建议将不胜感激

Node v8.6 不支持 "legacy" 协议。您应该使用 "inspector" 协议。

我 运行 在使用 "legacy" 协议的同时 运行 Hello World Extension 遇到了同样的问题。稍作搜索后,我偶然发现了 this issue,并按照@weinand 的建议将我的 launch.json 文件更改为以下内容:

{
        "name": "Launch Extension",
        "type": "extensionHost", 
        "request": "launch",
        "runtimeExecutable": "${execPath}",
        "args": [ "--extensionDevelopmentPath=${workspaceRoot}" ],
        "outFiles": [ "${workspaceRoot}/out/src/**/*.js" ]
}
  • 使用节点 8.9.1
  • 为代码使用了最新版本的 yeoman 生成器。