ionic无法加载插件引发安装

时间:2019-04-06 21:14:41

标签: angular ionic-framework npm cordova-plugins ionic-native

我有一个使用ionic制作的应用,安装插件时出现此错误

core.js:1449 ERROR TypeError: Object(...) is not a function
    at AppRate.set [as preferences] (index.js:31)
    at MyApp.webpackJsonp.259.MyApp.initializeApp (app.component.ts:32)
    at new MyApp (app.component.ts:19)
    at createClass (core.js:12491)
    at createDirectiveInstance (core.js:12326)
    at createViewNodes (core.js:13784)
    at createRootView (core.js:13673)
    at Object.createProdRootView [as createRootView] (core.js:14366)
    at ComponentFactory_.create (core.js:11278)
    at ComponentFactoryBoundToModule.create (core.js:4030)

对于我来说,我尝试添加AppRate插件,我在app.modle.ts和app.componets.ts中添加了该插件,如下所示的代码

import { Component, ViewChild } from '@angular/core';
import { Nav, Platform } from 'ionic-angular';
import { StatusBar } from '@ionic-native/status-bar';
import { SplashScreen } from '@ionic-native/splash-screen';
import {enableProdMode} from '@angular/core';
import { AppRate } from '@ionic-native/app-rate/ngx';


@Component({
  templateUrl: 'app.html'
})
export class MyApp {
  @ViewChild(Nav) nav: Nav;

  rootPage: any = 'MenuPage';


  constructor(public platform: Platform, public statusBar: StatusBar, public splashScreen: SplashScreen, private appRate: AppRate) {
    this.initializeApp();

  }

  initializeApp() {
    this.platform.ready().then(() => {
      // Okay, so the platform is ready and our plugins are available.
      // Here you can do any higher level native things you might need.
      this.statusBar.styleDefault();
      this.splashScreen.hide();
    });

    // or, override the whole preferences object
  this.appRate.preferences = {
    usesUntilPrompt: 3,
    storeAppURL: {
    ios: '<app_id>',
    android: 'market://details?id=<package_name>',
    windows: 'ms-windows-store://review/?ProductId=<store_id>'
    }
  }

this.appRate.promptForRating(false);
  }
}
enableProdMode();

我使用ionic框架文档来安装插件

ionic cordova plugin add cordova-plugin-apprate
npm install @ionic-native/app-rate

在安装过程中我得到了警告

npm WARN @ionic-native/app-rate@5.3.0 requires a peer of rxjs@^6.3.0 but none is installed. You must install peer dependencies yourself.
npm WARN @ionic-native/app-rate@5.3.0 requires a peer of @ionic-native/core@^5.1.0 but none is installed. You must install peer dependencies yourself

我确实从Mac重新安装了node.js,npm和ionic cordova,但仍然遇到相同的问题,我在Mac OS Mojave上使用ionic4。

1 个答案:

答案 0 :(得分:0)

您需要像这样降低您的应用费率插件版本:

nom install @ionic-native/app-rate@4.3.1

您的插件版本太高(离子5)。