Using Web Firebase SDK in Expo Snack
Published in
1 min readAug 13, 2018
TL;DR: if (!firebase.apps.length) firebase.initializeApp({ … });
instead of firebase.initializeApp({ … });
If you have tried using Firebase in a snack.expo.io you may have noticed that the hot reloading will cause it to throw errors and not function properly.
Device: (78:20) Firebase: Firebase App named '[DEFAULT]' already exists (app/duplicate-app).
Evaluating module://Firebase/Fire.js
Evaluating module://Screens/Login.js
Evaluating module://AuthStateLayer.js
Evaluating module://App.js
Loading module://App.js
Fixing this is very simple. Just check to make sure the app hasn’t been initialized before calling firebase.initializeApp({ ... });
You can do that like this:
if (!firebase.apps.length) firebase.initializeApp({ ... });
It’s kinda upsetting that firebase doesn’t just throw a warning and tell you what to do. 🙃
Thanks for reading
Hope this helps — Tweet at me any questions, Medium comments are hard to reply to 😕