如何解决由于提供'@ ionic-native/AppVersion'或'.../ngx'并在调用任何AppVersion方法时出现异常而导致的问题? [英] How to fix problem due to providing '@ionic-native/AppVersion' or '.../ngx' and having exception when calling any methods of AppVersion?

查看:281
本文介绍了如何解决由于提供'@ ionic-native/AppVersion'或'.../ngx'并在调用任何AppVersion方法时出现异常而导致的问题?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我添加了AppVersion Ionic本机插件( https://ionicframework.com /docs/native/app-version#usage ). 尝试将其提供给我的app.module.ts后,我在编译时出现错误,例如"AppVersion不存在提供程序" ...

I've added the AppVersion Ionic native plugin (https://ionicframework.com/docs/native/app-version#usage). After try to provide it into my app.module.ts i've an error at compilation like "No provider exists for AppVersion" ...

我认为可能是从AppVersion的Ionic 4/最新版本开始,我需要遵循以下说明: https://ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module ,其中说要为插件提供到app.module.ts中,并具有如下所示的导入方式:

I thinking that maybe from Ionic 4/recent version of AppVersion, i need to follow this instructions : https://ionicframework.com/docs/native/#Add_Plugins_to_Your_App_Module which say to provide the plugin into the app.module.ts with a import like this :

import AppVersion from '@ionic-native/AppVersion/ngx'.

代码编译.完美的.但是可悲的是,在运行时我遇到了一个错误:

The code compile. Perfect. But sadly at runtime i have an error which say:

TypeError: Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"]) is not a function. (In 'Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"])(this, "getPackageName", {}, arguments)', 'Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"])' is an instance of Object) getPackageName — index.js:28...

TypeError: Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"]) is not a function. (In 'Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"])(this, "getPackageName", {}, arguments)', 'Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"])' is an instance of Object) getPackageName — index.js:28...

因此,对于这个耗时的问题,我的解决方案是获取适用于另一个项目的AppVersion的保留版本:

So my solution to this time-consuming problem, was to take an hold version of the AppVersion, which works on another project :

package.json:

...
"@ionic-native/app-version": "^4.18.0",
...
"cordova-plugin-app-version": "0.1.9",
...

有了这个,我可以正常地将插件导入到我的app.module.ts(import AppVersion from '@ionic-native/AppVersion')中,一切正常.

With this, i can import normally the plugin into my app.module.ts (import AppVersion from '@ionic-native/AppVersion') and everything is ok.

有我的堆栈的版本:

离子:

ionic(Ionic CLI):4.1.2(/usr/local/lib/node_modules/ionic) 离子框架:离子角3.9.2 @ ionic/app-scripts:3.1.11

ionic (Ionic CLI) : 4.1.2 (/usr/local/lib/node_modules/ionic) Ionic Framework : ionic-angular 3.9.2 @ionic/app-scripts : 3.1.11

科尔多瓦:

cordova(Cordova CLI):8.1.1(cordova-lib@8.1.0) Cordova平台:Android 7.1.1,iOS 4.5.5 Cordova插件:cordova-plugin-ionic-keyboard 2.1.3,cordova-plugin-ionic-webview 1.2.1(和其他8个插件)

cordova (Cordova CLI) : 8.1.1 (cordova-lib@8.1.0) Cordova Platforms : android 7.1.1, ios 4.5.5 Cordova Plugins : cordova-plugin-ionic-keyboard 2.1.3, cordova-plugin-ionic-webview 1.2.1, (and 8 other plugins)

系统:

Android SDK工具:26.1.1(/Users/maximedesogus/Library/Android/sdk/) ios部署:1.9.4 NodeJS:v8.12.0(/usr/local/bin/node) npm:6.4.1 作业系统:macOS Xcode:Xcode 10.1 Build版本10B61

Android SDK Tools : 26.1.1 (/Users/maximedesogus/Library/Android/sdk/) ios-deploy : 1.9.4 NodeJS : v8.12.0 (/usr/local/bin/node) npm : 6.4.1 OS : macOS Xcode : Xcode 10.1 Build version 10B61

推荐答案

降级您当前的App版本插件,要先删除该插件,然后再安装该插件,例如:

Downgrade your current App version plugin, to do that remove this plugin first after that install this plugin again like::

1) ionic cordova plugin add cordova-plugin-app-version 

2) npm i @ionic-native/app-version@4.8.0

这篇关于如何解决由于提供'@ ionic-native/AppVersion'或'.../ngx'并在调用任何AppVersion方法时出现异常而导致的问题?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆