【问题标题】:How to debug multiple node projects in vscode debugger?如何在 vscode 调试器中调试多个节点项目?
【发布时间】:2019-08-15 10:00:43
【问题描述】:

我在两个独立的工作区中有两个独立的节点项目。我正在尝试使用 vscode 调试器调试项目,但我一次只能调试一个项目。如果我在启动第一个项目的调试器后尝试启动第二个项目的调试器,vscode 调试器会再次重新启动第一个项目。

我已经阅读了各种教程和 vscode 文档以进行 nodejs 的调试和 vscode 调试,但无济于事。以下是两个项目的启动配置。

项目1(堡垒):

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch fort",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "start"
            ],
            "envFile": "${workspaceFolder}/.env",
            "port": 9229
        }
    ]
}

package.jsonscripts 属性的值

"scripts": {
    "start": "node --inspect app.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  }

项目2(用户管理):

{
    "version": "0.2.0",
    "configurations": [
        {
            "type": "node",
            "request": "launch",
            "name": "Launch User Management",
            "runtimeExecutable": "npm",
            "runtimeArgs": [
                "start"
            ],
            "envFile": "${workspaceFolder}/.env",
            "port": 9229
        }
    ]
}

package.jsonscripts 属性的值

"scripts": {
    "start": "node --inspect server.js",
    "test": "echo \"Error: no test specified\" && exit 1"
  }

根据我在阅读 vscode 文档后的理解,如果我在工作区的 .vscode 文件夹中存在单独的 launch.json,则该特定配置将用于启动调试器。

也许我在文档中遗漏了一些东西,但我已经投入了足够的时间并且无法找到解决方案。

【问题讨论】:

    标签: node.js visual-studio-code vscode-settings vscode-debugger


    【解决方案1】:

    您需要使用两个单独的端口来连接调试器,例如:

    项目一:

    {
        "version": "0.2.0",
        "configurations": [
            {
                "type": "node",
                "request": "launch",
                "name": "Launch fort",
                "runtimeExecutable": "npm",
                "runtimeArgs": [
                    "start"
                ],
                "envFile": "${workspaceFolder}/.env",
                "port": 9228
            }
        ]
    }
    

    或者如果你想附加到进程:

    {
            "type": "node",
            "request": "attach",
            "name": "Attach",
            "port": 9228
    }
    

    在端口 9228 上启动节点检查:

    node --inspect=9228 index.js
    

    您可以为第二个项目保留默认值。

    【讨论】:

      猜你喜欢
      • 2019-03-15
      • 2019-04-20
      • 1970-01-01
      • 2017-05-25
      • 2016-01-24
      • 2022-08-18
      • 1970-01-01
      • 1970-01-01
      • 2022-11-04
      相关资源
      最近更新 更多