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

我遍历了各种教程和vscode文档,以进行调试和针对Node.js的vscode调试,但都无济于事。以下是两个项目的启动配置。

项目1(努力):

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


scriptspackage.json属性的值

"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
        }
    ]
}


scriptspackage.json属性的值

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


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

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

最佳答案

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

项目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


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

10-01 03:32
查看更多