我有一个与 nodemon 一起运行的 Express Nodejs 应用程序,但是当应用程序崩溃时,控制台中没有记录错误消息:
这是我的index.js 文件:
/* eslint-disable */
require("babel-register");
require('./server.js');
我不认为这是一个 nodemon
问题,因为当我删除 babel
时,控制台会显示“import”未定义的错误消息:
目前我使用 babel
{
"presets": ["env"],
"plugins": [
["transform-runtime", {
"helpers": false,
"polyfill": false,
"regenerator": true,
"moduleName": "babel-runtime"
}]
]
}
因为ReferenceError:regeneratorRuntime未定义
我尝试过切换 Node 版本,但没有成功。当前 Node 版本v8.10.0
如果有人能帮助我,我将非常感激。如果没有错误信息,调试起来真的很痛苦。
最佳答案
对于那些遇到同样问题的人,我最终解决了这个问题:
/* eslint-disable */
require("babel-register");
try{
require('./server.js');
} catch (e) {
console.log(e)
}
如果这仍然不起作用,那么也可以通过以下方式监听 unhandledRejection
和 uncaughtException
:
process
.on('unhandledRejection', (reason, p) => {
console.error(reason, 'Unhandled Rejection at Promise', p);
})
.on('uncaughtException', err => {
console.error(err, 'Uncaught Exception thrown');
process.exit(1);
});
关于node.js - 使用 Nodemon 和 babel 时 Express Nodejs 应用程序崩溃且没有错误消息,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/50151012/