Closed
Description
Related to: firebase/firebase-js-sdk#2054
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 more import admin from 'firebase-admin'
All my imports look like this now:
import {https} from 'firebase-functions';
import {initializeApp as adminInitializeApp, credential, ServiceAccount} from 'firebase-admin'
import {initializeApp as firebaseInitializeApp} from "firebase";
I'm referencing database from my initialized app:
const FIREBASE_CONFIG = process.env.FIREBASE_CONFIG || {} as any;
const adminConfig = JSON.parse(FIREBASE_CONFIG);
adminConfig.credential = credential.cert(serviceAccount as ServiceAccount);
const firebaseClientApp = firebaseInitializeApp(clientAccount);
const firebaseAdminApp = adminInitializeApp(adminConfig);
firebaseAdminApp.database()...
I'm still getting this error...
> FirebaseError: Firebase: Firebase service named 'database' already registered (app/duplicate-service).
> at Object.registerService (/functions/node_modules/@firebase/app/dist/index.node.cjs.js:375:33)
> at registerDatabase (/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15248:39)
> at Object.<anonymous> (/functions/node_modules/@firebase/database/dist/index.node.cjs.js:15271:5)
> at Module._compile (internal/modules/cjs/loader.js:776:30)
> at Object.Module._extensions..js (internal/modules/cjs/loader.js:787:10)
> at Module.load (internal/modules/cjs/loader.js:643:32)
> at Function.Module._load (internal/modules/cjs/loader.js:556:12)
> at Module.require (internal/modules/cjs/loader.js:683:19)
> at require (internal/modules/cjs/helpers.js:16:16)
> at DatabaseService.getDatabase (/functions/node_modules/firebase-admin/lib/database/database.js:64:24) {
> code: 'app/duplicate-service',
> name: 'FirebaseError',
> appName: 'database'
> }
There is no way to use both Admin SDK and Firebase JS SDK in firebase cloud functions with this error.