![](/img/trans.png)
[英]VSCode - How to debug a Node program that starts its own debugger, using a launch configuration?
[英]How to debug multiple node projects in vscode debugger?
我在两个单独的工作区中有两个单独的节点项目。 我正在尝试使用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.json
scripts
属性的值
"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.json
scripts
属性的值
"scripts": {
"start": "node --inspect server.js",
"test": "echo \"Error: no test specified\" && exit 1"
}
根据我对vscode文档的理解,如果我在工作区的.vscode
文件夹中存在单独的launch.json
,则将使用特定的配置来启动调试器。
也许我在文档中缺少了一些东西,但是我投入了足够的时间并且无法找到解决方案。
您需要使用两个单独的端口来连接调试器,例如:
项目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
您可以保留第二个项目的默认值。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.