The default Firebase app already exists. This means you called initializeApp() more than once
See original GitHub issue[REQUIRED] Environment info
firebase-tools: 7.1.0
Platform: Windows 10
[REQUIRED] Test case
import * as functions from 'firebase-functions';
import express from 'express';
import admin from "firebase-admin"
admin.initializeApp(functions.config())
console.log('Firebase Environment setup success')
const app1 = express()
app1.get("*", (request, response) => {
response.send("bar")
})
const foo = functions.https.onRequest(app1)
module.exports = {
foo
}
[REQUIRED] Steps to reproduce
Run
firebase emulators:start --only functions
visit the url of the function on your browser
[REQUIRED] Expected behavior
initializeApp should be called only once
[REQUIRED] Actual behavior
initializeApp is called everytime the url is called
! Error: 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. at FirebaseAppError.FirebaseError [as constructor] (C:\Users\Business\PhpstormProjects\gantt-flexx\node-server\node_modules\firebase-admin\lib\utils\error.js:42:28) at FirebaseAppError.PrefixedFirebaseError [as constructor] (C:\Users\Business\PhpstormProjects\gantt-flexx\node-server\node_modules\firebase-admin\lib\utils\error.js:88:28) at new FirebaseAppError (C:\Users\Business\PhpstormProjects\gantt-flexx\node-server\node_modules\firebase-admin\lib\utils\error.js:122:28) at FirebaseNamespaceInternals.initializeApp (C:\Users\Business\PhpstormProjects\gantt-flexx\node-server\node_modules\firebase-admin\lib\firebase-namespace.js:68:23) at FirebaseNamespace.initializeApp (C:\Users\Business\PhpstormProjects\gantt-flexx\node-server\node_modules\firebase-admin\lib\firebase-namespace.js:392:30) at Proxy. (C:\Users\Business\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:338:51) at C:\Users\Business\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:641:30 at Generator.next () at fulfilled (C:\Users\Business\AppData\Roaming\npm\node_modules\firebase-tools\lib\emulator\functionsEmulatorRuntime.js:4:58) at process._tickCallback (internal/process/next_tick.js:68:7) ! Your function was killed because it raised an unhandled error.
Issue Analytics
- State:
- Created 4 years ago
- Reactions:5
- Comments:18 (4 by maintainers)
here’s what I’m doing:
Tente:
!firebaseAdmin.apps.length ? firebaseAdmin.initializeApp() : firebaseAdmin.app();
outry{ firebaseAdmin.initializeApp() } catch(err){ firebaseAdmin.app() }