如何找出未处理的承诺拒绝发生在哪里?
快速序言:我了解承诺,我明白解决和拒绝。 这不是问题。
(node:14104) UnhandledPromiseRejectionWarning: Unhandled promise rejection (rejection id: 1): Error: "callback" argument must be a function (node:14104) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.\
我理解我的代码中的一个“callback”参数,这应该是一个函数,不是。 这也不是我的问题。
如何find未处理的拒绝发生的代码行?
节点的“未处理的拒绝”事件应该解决你的谜团:
process.on('unhandledRejection', (reason, promise) => { console.warn('Unhandled promise rejection:', promise, 'reason:', reason.stack || reason); });