[英]NodeJS breakpoints sometimes not working
We are building a NodeJS 5.5.0 app using the --harmony
command line flag to enable ES6. 我们正在使用
--harmony
命令行标志构建一个NodeJS 5.5.0应用程序以启用ES6。 It is a very simple API proxying app so there is no data layer or front-end apart from the API responses themselves. 这是一个非常简单的API代理应用程序,因此除了API响应本身之外,没有数据层或前端。 The app is tied together with connect, using Swagger for the API itself.
该应用程序通过Swagger用于API本身与connect捆绑在一起。 I am using IntelliJ 15 and everything is working well apart from debugging failing to consistently hit my breakpoints.
我正在使用IntelliJ 15,除了调试无法始终达到我的断点之外,其他所有功能都运行良好。 I am finding this quite frustrating and a waste of dev time - perhaps I am missing something here as am new to the Node environment?
我发现这很令人沮丧并且浪费了开发时间-也许我在这里错过了Node环境的新功能?
Here is my specific example: 这是我的具体示例:
app.js: app.js:
// requires here
swaggerTools.initializeMiddleware(swaggerDoc, function (middleware) {
// Interpret Swagger resources and attach metadata to request
app.use(middleware.swaggerMetadata());
// Validate Swagger requests
app.use(middleware.swaggerValidator());
// Route validated requests to appropriate controller
app.use(middleware.swaggerRouter(options));
// Serve the Swagger documents and Swagger UI
app.use(middleware.swaggerUi());
// Start the server
http.createServer(app).listen(serverPort, function () {
console.log('Server is listening on port %d', serverPort);
});
});
module.exports = app;
And then somewhere along the line we are using a transformer with object-mapper
that runs on every API call: 然后沿线使用在每个API调用上运行的带有
object-mapper
的转换object-mapper
:
transformer.js: Transformer.js:
'use strict';
(function () {
var util = require('util');
//==> breakpoint #1 on the line below, successfully hit when the app launches
module.exports = function (req, res, data, next) {
console.log('GOT HERE!');
//==> breakpoint #2 on the line below never hit but app hangs here
var operation = req.swagger.operation;
// more code here
};
}).call(this);
Breakpoint #1 always works when the app launches, I skip it and make a call and 'GOT HERE!' 断点1始终在应用程序启动时起作用,我跳过它并打个电话,然后点击“开始!”。 is printed in the console as I would expect.
正如我所期望的那样在控制台中打印。 The app hangs here indefinitely but I can't inspect any variables and the IDE doesn't register that it has hit the breakpoint.
该应用程序会无限期地挂在这里,但我无法检查任何变量,并且IDE不会注册它已达到断点。 We've tested this outside of the IDE with
node-inspector
, Chrome tools and the native interactive node debugger but the same issue is present. 我们已经在IDE外部使用
node-inspector
,Chrome工具和本机交互式节点调试器对此进行了测试,但是存在相同的问题。 I have also tested this on multiple versions of Node 4 and 5. 我还在节点4和5的多个版本上进行了测试。
We've had to wrap most of our files with a function wrapper for the time being as we're using blanket for code coverage and it doesn't work without this. 暂时,我们不得不使用函数包装器来包装大多数文件,因为我们正在使用毯子进行代码覆盖,没有它就无法工作。 I have tried removing the function wrapper in transformer.js above but the debugger still doesn't hit breakpoint #2.
我曾尝试在上面的transformer.js中删除函数包装器,但调试器仍未达到断点2。
Can anyone please offer some insight on this as I'm out of ideas? 当我没主意时,有人可以提供一些见解吗?
I have found the cause of this. 我找到了原因。 It seems there is a potential bug with the Node debugger when it hits any line with
util.inspect()
on it it will hang there. 当节点调试器碰到任何带有
util.inspect()
,它都将挂在那里,这似乎是一个潜在的错误。
I have confirmed this is an issue in the latest versions of Node 4.2.6 and 5.5.0 as well as nightly builds 5.5.1 and 6.0.0. 我已经确认这是最新版本的Node 4.2.6和5.5.0以及每夜构建5.5.1和6.0.0中的问题。
See https://github.com/nodejs/node/issues/4906 参见https://github.com/nodejs/node/issues/4906
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.