【发布时间】:2018-08-15 13:10:49
【问题描述】:
基本上,我无法将 VS Code 调试器附加到我的 Node 应用程序中的子进程。它只附加到主进程。
我已经阅读并关注了这里的官方文档 - https://code.visualstudio.com/docs/nodejs/nodejs-debugging#_automatically-attach-debugger-to-nodejs-subprocesses
我的节点代码使用集群模块来分叉一些工人。非常标准,它遵循集群示例代码。
if (cluster.isMaster) {
console.log(`Master process ${process.pid} starting...`);
for (let i = 0; i < numCPUs && i < maxNumThreads; i++) {
cluster.fork(); // Create a worker
}
} else {
startClusterWorkers();
}
function startClusterWorkers() {
// xxxxxx
}
我的 launch.json 已经定义了 autoAttachChildProcesses。
{
"version": "0.2.0",
"configurations": [
{
"type": "node",
"request": "launch",
"name": "Launch app.js",
"program": "${workspaceFolder}\\app.js",
"restart": true,
"autoAttachChildProcesses": true,
// "console": "integratedTerminal"
},
{
"type": "node",
"request": "launch",
"name": "Launch test.js",
"program": "${workspaceFolder}\\test.js"
}
]
}
但与官方文档不同,子进程不会出现在调用堆栈或浮动调试器控件中。调试器控制台也没有说明子进程。当然,在子进程中设置的断点(上面的 startClusterWorkers() 函数)不起作用。
Debugging with inspector protocol because Node.js v8.9.1 was detected.
node --inspect-brk=31761 app.js
Debugger listening on ws://127.0.0.1:31761/54919117-38ae-4455-82c6-e21ade314bdd
Master process 10096 starting...
请知道我做错了什么?
VS Code 1.20.1 版(最新) 节点版本 8.9.1
【问题讨论】:
标签: node.js visual-studio-code