ionic-framework icon indicating copy to clipboard operation
ionic-framework copied to clipboard

Using Firebase 3.4.1 with Ionic 2 Getting Error : Cannot read property 'navigator' of undefined

Open junaidahmed93 opened this issue 10 years ago • 4 comments

Hello Everyone I am using Firebase 3.4.1 in ionic 2 app During Building i Got Error

[20:15:06]  rollup: Export 'initializeApp' is not defined by '\.tmp\app\app.component.js'                          

[20:15:06]  rollup: Use of `eval` (in \node_modules\firebase\auth.js) is strongly discouraged, as it poses security
 risks and may cause issues with minification. See https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval for more details              

[20:15:06]  rollup: Use of `eval` (in \node_modules\firebase\database.js) is strongly discouraged, as it poses secu
rity risks and may cause issues with minification. See https://github.com/rollup/rollup/wiki/Troubleshooting#avoiding-eval for more details

After Building App console shows Cannot read property 'navigator' of undefined

junaidahmed93 avatar Oct 03 '16 15:10 junaidahmed93

In which place do you call firebase#initializeApp? I placed it in the constructor of 'app.ts' and outside the call 'platform.ready' and worked for me. Like so:

_[other imports]_

import * as firebase from 'firebase';

export class MyApp {

  public rootPage: any;

  constructor(private platform: Platform) {
    this.rootPage = TabsPage;

    var config = {
      apiKey: "XXXXXXXXXXXXXXXX",
      authDomain: "XXXXXXXXXXXXXXXX",
      databaseURL: "XXXXXXXXXXXXXXXX",
      storageBucket: "XXXXXXXXXXXXXXXX",
      messagingSenderId: "XXXXXXXXXXXXXXXX"
    };
    firebase.initializeApp(config);

    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.
      StatusBar.styleDefault();
    });
  }
}

AntonioRossi avatar Oct 03 '16 19:10 AntonioRossi

@AntonioRossi app.ts is replaced with app.component.ts in Ionic2 RC 0 I was configuring the config object in provider/service and then importing in app.component.ts But now i have moved all that code in the app.component.ts. Still no luck, Error Is same, Thanks

junaidahmed93 avatar Oct 03 '16 19:10 junaidahmed93

Hello all! Thanks for using Ionic! You can check out this link for how to use firebase with RC.0. We are also currently working on our own docs on how to use third party libraries written in commonjs with Ionic 2. Thanks!

jgw96 avatar Oct 04 '16 14:10 jgw96

@jgw96 Hi Justin - is there a good way to use Firebase without AngularFire?

philipphalder avatar Oct 14 '16 11:10 philipphalder