Visual Studio代码 - 10000毫秒后无法连接到运行时进程超时

jdo*_*doe 13 node.js visual-studio-code

我试图从VS Code中的调试控制台启动该程序,但是出现了错误 cannot connect to runtime process timeout after 10000 ms

launch.json

   "version": "0.2.0",
    "configurations": [

        {
            "type": "node",
            "request": "attach",
            "protocol": "inspector",
            "name": "Attach by Process ID",
            "processId": "${command:PickProcess}"
        },
        {
            "type": "node",
            "request": "attach",
            "protocol": "inspector",
            "name": "Attach",
            "port": 9229
        },
        {
            "type": "node",
            "request": "launch",
            "port":9230,
            "name": "Launch Program",
            "program": "${workspaceFolder}\\bin\\www"
        }
    ]
}
Run Code Online (Sandbox Code Playgroud)

我正在尝试使用VS Code进行调试,但是遇到了如下错误.我正确配置我的launch.json吗?

错误截图

Rob*_*ens 11

"启动"类型配置不需要指定端口.设置port参数时,它假定您的启动配置将包含该端口的--inspect参数.

如果由于某种原因必须指定确切的端口,那么可以包括--inspect参数,如:

    {
        "type": "node",
        "request": "launch",
        "port":9230,
        "runtimeArgs": ["--inspect=9230"],
        "name": "Launch Program",
        "program": "${workspaceFolder}\\bin\\www"
    }
Run Code Online (Sandbox Code Playgroud)

但我建议只从启动配置中删除"端口".


jar*_*raj 5

我正在使用nodemon和babel启动Visual Studio代码,并发现您需要确保在package.json和launch.json中具有与Visual Studio代码兼容的配置。

确实,这意味着您需要找到一个配置,该配置允许您从Powershell以及Windows中的gitbash启动常规配置。这是我想出的:

在package.json中

  "scripts": {
    "start": "nodemon --inspect --exec babel-node -- index.js",
  },
Run Code Online (Sandbox Code Playgroud)

在launch.json中

{
    "version": "0.2.0",
    "configurations": [{
        "type": "node",
        "request": "launch",
        "name": "Launch via Babel (works)",
        "cwd": "${workspaceRoot}",
        "port": 9229,
        "program": "",
        "runtimeExecutable": "npm",
        "console": "integratedTerminal",
        "runtimeArgs": [
            "start"
        ]
    }
    ]
}
Run Code Online (Sandbox Code Playgroud)

当节点启动时,您应该会看到类似以下内容的内容:

PS F:\noise\bookworm-api> cd 'F:\noise\bookworm-api'; & 'F:\applications\nodejs\npm.cmd' 'start'

> bookworm-api@1.0.0 start F:\noise\bookworm-api
> nodemon --inspect --exec babel-node -- index.js

[nodemon] 1.18.4
[nodemon] to restart at any time, enter `rs`
[nodemon] watching: *.*
[nodemon] starting `babel-node --inspect index.js`
Debugger listening on ws://127.0.0.1:9229/e6e1ee3c-9b55-462e-b6db-4cf67221245e
For help see https://nodejs.org/en/docs/inspector
Debugger attached.
Running on localhost:3333
Run Code Online (Sandbox Code Playgroud)

您真正要寻找的是:

Debugger listening on ws://127.0.0.1:9229/e6e1ee3c-9b55-462e-b6db-4cf67221245e
Run Code Online (Sandbox Code Playgroud)

此输出表明您的调试器正在端口9229上等待WebSockets请求。您可以通过以下方式将其传达给Visual Studio代码:

"port": 9229,
Run Code Online (Sandbox Code Playgroud)

在您的launch.json文件中。

如果看不到调试服务器正在等待的端口,则可能需要将--inspect标志添加到节点中的启动命令。