0

I am using Firebase UI in my React App to allow users to login. Currently I have installed the firebaseui library using npm and then I use

var firebaseui = require('firebaseui')

at the top of my component and then I set up the ui with:

var ui = new firebaseui.auth.AuthUI(firebase.auth())

where firebase is defined and configured. All works ok.

if I try to use a cdn instead of the npm install I was expecting to just replace the first line with:

var firebaseui = window.firebaseui

This doesn't error until we get to the later statement initializing the ui variable which now errors with "firebase is not defined" - but the firebase variable hasn't been changed!

window.firebaseui.auth.AuthUI is indeed a function (seen when debugging) but why is firebase now not defined when it is when the firebaseui is set using require()?

thanks

Frank van Puffelen
  • 565,676
  • 79
  • 828
  • 807
user2047485
  • 391
  • 5
  • 20
  • `require()` is mainly supposed to pull from your local `node_modules` folder. It's not supposed to ever execute in the browser. if you use a CDN reference, you have to use the lower quality global variable approach and just reference the magic global `firebase` directly – Andy Ray Apr 27 '18 at 16:50
  • but I am using require for firebase which is in node_modules and the cdn for firebaseui - can I not mix them like this? Originally I was using require for both and that worked. Why can't I change the firebaseui one to a cdn and leave the other one? The reason I am trying this is that eventually I have to dynamically load the firebaseui one depending on the language selected but I can't even try that if I can't get this bit working – user2047485 Apr 30 '18 at 09:15

0 Answers0