首页 > 解决方案 > 调用 ionic cordova build --release android 时出现 UnhandledPromiseRejectionWarning

问题描述

每当我尝试使用时,我都会收到此错误消息 ionic cordova build --release android

(节点:1512) UnhandledPromiseRejectionWarning:未处理的承诺拒绝。此错误源于在没有 catch 块的情况下抛出异步函数内部,或拒绝未使用 .catch() 处理的承诺。(拒绝 ID:1)(节点:1512)[DEP0018] DeprecationWarning:不推荐使用未处理的承诺拒绝。将来,未处理的 Promise 拒绝将使用非零退出代码终止 Node.js 进程。

感谢您的回答!

标签: ionic-framework

解决方案


当你调用一个 promise 并且没有向它添加一个 catch 块时,这个警告就会发生。当 promise 调用被拒绝时,会调用 catch 块。

例如:

var foo = function () {
    fooPromise
        .then(function (res) {
            // Do something with the response of the promise
        })
        .catch(function (err) {
            // handle the error 
        });
};

查看 Javascript 文档以获取更多信息:这里


推荐阅读