繁体   English   中英

未处理的承诺拒绝警告(科尔多瓦角)

[英]Unhandled Promise Rejection Warning (Cordova Angular)

当我在cmd cordova run android时执行时,它返回:

Android Studio project detected
(node:6824) UnhandledPromiseRejectionWarning: Unhandled Promise Rejection (rejection id: 1): Operation Failed
(node: 6824) [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.

如果您对我有任何建议,我不明白问题所在。 我已经在stackoverflow上阅读了有关此问题的其他答案,但是..这是我下面的代码

module.exports = function(ctx) {
// make sure android platform is part of build 
if (ctx.opts.platforms.indexOf('android') < 0) {
    return;
}
var fs = ctx.requireCordovaModule('fs'),
    path = ctx.requireCordovaModule('path'),
    deferral = ctx.requireCordovaModule('q').defer();

var platformRoot = path.join(ctx.opts.projectRoot, 'platforms/android');
var apkFileLocation = path.join(platformRoot, 'build/outputs/apk/android-debug.apk');

fs.stat(apkFileLocation, function(err,stats) {
    if (err) {
         deferral.reject('Operation failed');
    } else {
        console.log('Size of ' + apkFileLocation + ' is ' + stats.size +' bytes');
        deferral.resolve();
    }
});

return deferral.promise;};

感谢您的帮助。

该错误表示您需要处理从promise抛出的异常。

promise.then(...).catch(...)

如果无法做到这一点,则需要避免deferral.reject

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM