property 'apps' is not included in return value from 'firebase-admin'

Viewed 39

I'm trying to decide whether of not calling initializeApp() is needed based on the property 'apps' returning from 'firebase-admin'. On the first try it worked as expected, but afterwards this error began to arise no matter how many times I tried.

Error:

uncaughtException FirebaseAppError: The default Firebase app already exists. This means you called initializeApp() more than once without providing an app name as the second argument. In most cases you only need to call initializeApp() once. But if you do want to initialize multiple apps, pass a second argument to initializeApp() to give each app a unique name.

Code:

import * as firebase from 'firebase-admin';
console.log(firebase); // add this on second try
if (!firebase.apps.length) {
  firebase.initializeApp({
      credential: firebase.credential.cert(some config here),
      databaseURL: 'some url here',
  });
}

when I see the console, output is like:

FirebaseNamespace {
  __esModule: true,
  credential: {
    cert: [Function],
    refreshToken: [Function],
    applicationDefault: [Function]
  },
  SDK_VERSION: '9.5.0',
  Promise: [Function: Promise],
  INTERNAL: FirebaseNamespaceInternals { firebase_: [Circular], apps_: {} },
  default: [Circular]
}

There's no such property as 'apps'. Does anyone knows why this property does not exist?

UPDATE:

I've solved this problem by myself. It was an easy mistake.

After inspecting codes, I found an another place where the exact same logic is written. This logic runs second times, so the second one is giving this error.

0 Answers
Related