Can't use initFirebase() on 1.1.3 [Firebase isn't initialised] [Solutions proposed] #822
Description
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
thennpm install @ionic-native/firebase --save
if it doesn't work
- try upgrading to 1.1.3 for @DomCostantino's trick :
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)