![](/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.