cordova-plugin-firebase: Can't use initFirebase() on 1.1.3 [Firebase isn't initialised] [Solutions proposed]

I just updated cordova-plugin-firebase to 1.1.3 and tried to use the initFirebase() method to get rid of the ‘Firebase isn’t initialised’ error (note that the error got a typo in console log).

I’m getting the following error : Uncaught (in promise): TypeError: _this.firebase.initFirebase is not a function TypeError: _this.firebase.initFirebase is not a function

my code : (note that this code [without initFirebase()] is totally working on another computer.
import {Firebase} from "@ionic-native/firebase"; public start() { return this.platform.ready().then(() => { this.firebase.initFirebase(); this.firebase.getToken().then(token => { console.log(token) this.api.post('tg.php', {token}).subscribe(() => { }); } ).catch(err => console.log(err)); }); }

***** EDIT ***** :

For those encountering the same problem, here is a walkthrough which seems to help most people :

  • downgrading cordova-plugin-firebase to 0.1.18 which can be done like this : cordova plugin rm cordova-plugin-firebase cordova plugin add cordova-plugin-firebase@0.1.18 npm install --save @ionic-native/firebase

if it doesn’t work

  • uninstalling and reinstalling the plugin with cordova plugin add cordova-plugin-firebase@1.0.5 then npm install @ionic-native/firebase --save

if it doesn’t work

declare var FirebasePlugin : any;

and then insert the cordova script include in your index.html file

<script type="text/javascript" src="cordova.js"></script>

and using the plugin like this:

FirebasePlugin.initFirebase();

For those needing a practical example of how to insert it in your own code, here is a snippet courtesy of @tgensol :

observableFromEvent(document, 'deviceready').pipe(first()).subscribe(() => { FirebasePlugin.initFirebase(); FirebasePlugin.initAnalytics(); })

Depending on how you coded your application, this may have to go in your home.ts /or/ typescript associated with the page calling it /or/ in the provider calling for the getToken() functio.

If the problem isn’t solved with this step by step, write down the encountered problems here so we can help troubleshoot for you and others.

[important note : for people having a hard time downgrading, try deleting manually plugins and platforms folders (after backuping them/!), then after plugin installation go for a : cordova platform add android]

Good luck

(follow the thread for credits of contributors)

About this issue

  • Original URL
  • State: closed
  • Created 6 years ago
  • Reactions: 4
  • Comments: 29 (8 by maintainers)

Most upvoted comments

I had this same issue. Got rid of the ‘Firebase isn’t initialised’ error by downgrading to 1.0.5:

cordova plugin remove cordova-plugin-firebase
cordova plugin add cordova-plugin-firebase@1.0.5

Guys, confirmed. Using Cordova 8, Cordova Android 7.1.1 and Cordova Plugin Firebase 1.1.3:

You just need to add the FirebasePlugin.initFirebase method before using Firebase. And then in it’s success callback get your token:

IE:

//Inits Firebase
FirebasePlugin.initFirebase(
    function(){
        //Subscribes for token refresh event
        window.FirebasePlugin.onTokenRefresh(
            function(token) {
                console.log("Device token refresh: " + token);
                //Your token handling functions
            }, 
            function(error) {
                console.error("Firebase error: " + error);
            }
        );
    }, 
    function(error) {
        console.error("Firebase error: " + error);
    }
);

Same problem. I created a stackoverflow question with a 50 reputation bounty

https://stackoverflow.com/questions/52140850/firebase-isnt-initialised-on-ios-ionic/52186436

Based on @BrainOverflown, I managed to make it working (the 1.1.3 version) by calling these methods in my app.components.ts, just after the device is ready

observableFromEvent(document, ‘deviceready’).pipe(first()).subscribe(() => { FirebasePlugin.initFirebase(); FirebasePlugin.initAnalytics(); })

You also need to declare Firebase Plugin to use it

declare var FirebasePlugin: any;

Best

Was able to use the FirebasePlugin.getToken() function after I called FirebasePlugin.initFirebase() successfully, though if I try to push out a notification through the FCM console, I get an error stating Unregistered registration token. Hmm.

@SimonKomlos I tried 1.0.5 and it does work. But for some configurations going down to 0.1.18 may be useful so people reading this better try both if 1.0.5 doesn’t work i guess…

Downgrading to 1.0.5 worked for me!

@SimonKomlos Yes, but people should be very careful because when you install by editing your config.xml, it will automatically be renammed from “1.0.5” to “^1.0.5” (this caracter is making cordova build the platform with latest version and not 1.0.5).