如何解决由于提供“@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?

查看:16
本文介绍了如何解决由于提供“@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" ...

我认为可能来自 Ionic 4/最新版本的 AppVersion,我需要遵循以下说明: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 :

从@ionic-native/AppVersion/ngx"导入 AppVersion.

代码编译.完美的.但遗憾的是在运行时我有一个错误说:

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

TypeError: Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"]) 不是函数.(在 'Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"])(this, "getPackageName", {}, arguments)' 中,'Object(__WEBPACK_IMPORTED_MODULE_1__ionic_native_core__["cordova"])' 是 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.

有我的堆栈的版本:

离子:

离子(离子 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.5Cordova 插件: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.4NodeJS : v8.12.0 (/usr/local/bin/node)npm:6.4.1操作系统:macOSXcode:Xcode 10.1 构建版本 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

推荐答案

降级您当前的应用程序版本插件,首先删除此插件,然后再次安装此插件,如::

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天全站免登陆