Plugin called before platform.ready() on --prod

Hello,
I’m developing an app that uses NativeStorage plugin. I’ve created a provider that has some methods that use this plugin and other classes uses this provider.
But when i tried to create the app with --prod this plugin is called before platform.ready(), resulting the message on the console:

Native: tried calling NativeStorage.getItem, but the NativeStorage plugin is not installed.
Install the NativeStorage plugin: ‘ionic cordova plugin add cordova-plugin-nativestorage’

How can i ensure that the provider is only called after platform.ready()?
I’m testing on one physical and one virtual android device and both of them show the same behaviour
Thanks

Environment info:

cli packages:

    @ionic/cli-utils  : 1.6.0 (/home/zaphod/desenvolvimento/project/node_modules/ionic/node_modules/@ionic/cli-utils)
    ionic (Ionic CLI) : 3.6.0 (/home/zaphod/desenvolvimento/project/node_modules/ionic)

global packages:

    Cordova CLI : 7.0.1 

local packages:

    @ionic/app-scripts              : 2.0.2
    @ionic/cli-plugin-cordova       : 1.4.1
    @ionic/cli-plugin-ionic-angular : 1.3.2
    Cordova Platforms               : android 6.2.3
    Ionic Framework                 : ionic-angular 3.5.3

System:

    Android SDK Tools : 25.2.5
    Node              : v8.1.2
    OS                : Linux 4.4
    npm               : 5.0.3 

Use platform.ready() as it is used in app.component.ts and wrap your plugin calls. Then they will only be executed after the platform is ready.

PS: Do you really need NativeStorage? Ionic Storage provides very similar functionality and also works in ionic serve (and doesn’t need additional native code)

Hello.
I did what you suggested and it work as expected. Thank you.
About the Ionic Storage. I didn’t know about it but thanks for the suggestion!

1 Like