关于Node.js v6.0.0上Visual Studio代码(F5)的问题

我有一些与Visual Studio的代码 集群的问题

编辑

如果我按Ctrl + F5它能正常工作,除了F5以外 ,我还需要使用Ctrl来启动命令吗?

看起来,VS Code Launch命令(F5)启动时,工作人员从不启动。 是否需要对.vscode / launch.json文件进行一些更改才能使群集能够正常工作。

实际代码从Node.js 6 api复制https://nodejs.org/api/cluster.html#cluster_cluster

npmtesting Windows命令提示符显示了这一点:

Master started Listening port 80 Listening port 80 Listening port 80 Listening port 80 

VS代码(F5)debugging控制台显示:

 node --debug-brk=7601 --nolazy index.js Debugger listening on port 7601 Master started Debugger listening on port 7602 Debugger listening on port 7603 Debugger listening on port 7604 Debugger listening on port 7605 

VS代码launch.json

 { "version": "0.2.0", "configurations": [ { "name": "Launch", "type": "node", "request": "launch", "program": "${workspaceRoot}/index.js", "stopOnEntry": false, "args": [], "cwd": "${workspaceRoot}", .......... 

index.js

 const cluster = require('cluster'); const http = require('http'); const numCPUs = require('os').cpus().length; if (cluster.isMaster) { // Fork workers. console.log('Master started') for (var i = 0; i < numCPUs; i++) { cluster.fork(); } cluster.on('exit', (worker, code, signal) => { console.log(`worker ${worker.process.pid} died`); }); } else { // Workers can share any TCP connection // In this case it is an HTTP server http.createServer((req, res) => { res.writeHead(200); res.end('hello world\n'); }).listen(80); console.log('Listening port 80') } 

我遇到过同样的问题。 Weinand在https://github.com/Microsoft/vscode/issues/3201中描述的第二个解决方法适用于我&#xFF1A;

从terminal启动节点,并使用VS Codedebugging器附加到节点上。

在terminal运行:node –debug app.js

然后select默认的“附加”启动configuration并附加到它。

如果您真的要debugging任何工作人员,而不仅仅是启动的第一个进程,则解决方法是首选方法。

我在Visual Studio Studio中使用Cluster有同样的问题。

我发现有一些肮脏的方法,使其工作。

Mac OS X:

/ Applications / Visual Studio Code.app/Contents/Resources/app/extensions/node-debug/out/node/nodeDebug.js

视窗:

C:\ Program Files(x86)\ Microsoft VS Code \ resources \ app \ extensions \ node-debug \ out \ node \ nodeDebug.js

改变这一点

 if (!this._noDebug) { launchArgs.push("--debug-brk=" + port); } 

 if (!this._noDebug) { launchArgs.push("--debug=" + port); } 

我知道这不是解决这个问题的最好方法,但是对我来说这是工作至今。