I’m trying to run the Firebase shell however I get the error:
FirebaseError: Firebase: Firebase service named ‘database’ already registered (app/duplicate-service).
My Firebase dependencies:
"firebase": "^6.3.4",
"firebase-admin": "^8.3.0",
"firebase-functions": "^3.0.2"
I initialize the Firebase in my index.js like:
admin.initializeApp(appConfig);
firebase.initializeApp(appConfig);
const rtdb = admin.database(admin.app());
const firestore = firebase.firestore(admin.app());
Possibly the same issue as, #2040, but was not able to resolve the issues by following those steps.
I just went through my entire codebase and carefully made sure that I’m at the latest versions of all my google dependencies.
I fixed every single one of my imports to only import exactly what was needed. No more
* as admin
or* as firebase
. Also no moreimport admin from 'firebase-admin'
All my imports look like this now:
I’m referencing database from my initialized app:
firebaseAdminApp.database()...
I’m still getting this error…
There is no way to use both Admin SDK and Firebase JS SDK in firebase cloud functions with this error.
Changing
const firebase = require('firebase')
toconst firebase = require('firebase/app')
allows me to test and deploy my firebase functions. However, the firebase shell gets stuck when I try to locally emulate my functions when I run firebase functions:shell.