firebase-tools: The default Firebase app already exists. This means you called initializeApp() more than once
[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.
About this issue
- Original URL
- State: closed
- Created 5 years ago
- Reactions: 8
- Comments: 19 (4 by maintainers)
here’s what I’m doing:
Tente:
!firebaseAdmin.apps.length ? firebaseAdmin.initializeApp() : firebaseAdmin.app();
outry{ firebaseAdmin.initializeApp() } catch(err){ firebaseAdmin.app() }
Hi. Using 9.1.0 version and still the same
Yes, 7.2.0 works. I was a bug with 7.1.0 then Thanks
Tolotra Samuel Randriakotonjanahary
https://tolotra.com
On Wed, Jul 24, 2019 at 8:47 PM Sam Stern notifications@github.com wrote:
I guess It depends on how you are using the AdminSDK, what works for me (as I’m using as modules) is this.
@markgoho that’s the slam dunk right there ;D thank you.
Doesn’t work for me unfortunately @markgoho admin.apps.length is an [object Object] So now it never gets in the if, and never initializes.
EDIT: I thought that was the problem, but actually I’m getting 1 app on the admin.apps array and that’s why it doesn’t enter the if.
EDIT 2: Nevermind, I was initializing the app inside the
exports.myFunction
so it always only worked the first time. Hope my “issue” helps someone doing the same mistake.I have the same issue.
When I deploy
firebase deploy --only functions --project staging
Error: Failed to load function definition from source: Failed to generate manifest from function source: 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.
I am using
firebase-tools: 10.9.2
,firebase-admin: 10.2.0
andfirebase-functions: 3.21.1
I usefirebase-functions/v1
andfirebase-functions/v2
, I only get this error when I export v2 functionsI have tried this and I still get the same error
EDIT: Found the issue it was caused by third-party imports