node.js - 使用 Nodemon 和 babel 时 Express Nodejs 应用程序崩溃且没有错误消息

标签 node.js error-handling console babeljs nodemon

我有一个与 nodemon 一起运行的 Express Nodejs 应用程序,但是当应用程序崩溃时,控制台中没有记录错误消息: enter image description here

这是我的index.js 文件:

/* eslint-disable */
require("babel-register");
require('./server.js');

我不认为这是一个 nodemon 问题,因为当我删除 babel 时,控制台会显示“import”未定义的错误消息: enter image description here

目前我使用 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)
}

如果这仍然不起作用,那么也可以通过以下方式监听 unhandledRejectionuncaughtException:

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/

相关文章:

node.js - 使用Webpack打包ES6模块

java - 未进入 tessract 方法 doOCR(File imageFile) 内部

c# - 如何在 C# 中将控制台输出写入控制台和文件?

Java/Swing : console component?

node.js - 如何在 Sails.js 中获取 ObjectID?

node.js - 我正在使用 React-native 和 Node js。在收到 Node js 的响应后,我无法从一个屏幕导航到另一个屏幕

node.js - firebase.database() 不是本地 Node 上的函数

mysql - mysql 错误代码的数值范围是多少?

asp.net-mvc - 如何使自定义错误页面出现在生产服务器上

validation - CakePHP的 “baked” date字段验证错误