NodeJS 6:如何查看整个错误堆栈跟踪?

njL*_*jLT 4 javascript node.js

而不是在编译/运行时收到承诺拒绝警告

npm start

(node:22996) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): SyntaxError: Unexpected identifier
Run Code Online (Sandbox Code Playgroud)

我可以获得整个堆栈跟踪,指出我的代码中出现错误的行,就像在 Nodejs 4 中那样?

SyntaxError: /Users/user/Documents/project/app.js: Unexpected token (30:57)
Run Code Online (Sandbox Code Playgroud)

Bre*_*loy 5

将以下内容添加到您的代码中以获得您期望的堆栈跟踪:

process.on('unhandledRejection', r => console.error(r));
Run Code Online (Sandbox Code Playgroud)

它会向您显示有错误的代码行。