Open
Description
[READ] Step 1: Are you in the right place?
This is a bug report.
[REQUIRED] Step 2: Describe your environment
- Operating System version: macOS Sonoma
- Firebase SDK version: 11.11.0
- Firebase Product: any
- Node.js version: 18.18.0
[REQUIRED] Step 3: Describe the problem
The top-level service accessors (auth()
, firestore()
) provided by the firebase-admin
don't work when provided an App object. However, the per-product accessors (getAuth()
, getFirestore()
) work fine.
Doesn't work:
import { auth, firestore } from "firebase-admin"
import { initializeApp } from "firebase-admin/app"
const firebase = initializeApp()
const authx = auth(firebase) // this fails
const firestorex = firestore(firebase) // also fails
// These do not fail when passed no args - they properly get the default app.
Full error when using accessors with an App instance looks like this:
/path/to/node_modules/firebase-admin/lib/app/firebase-namespace.js:136
return this.ensureApp(app).firestore();
^
TypeError: this.ensureApp(...).firestore is not a function
at fn (/path/to/scripts/node_modules/firebase-admin/lib/app/firebase-namespace.js:136:40)
at <anonymous> (/path/to/scripts/src/bootstrap_emulator.ts:8:20)
at Object.<anonymous> (path/to/scripts/src/bootstrap_emulator.ts:19:6)
at Module._compile (node:internal/modules/cjs/loader:1256:14)
at Object.S (/path/to/scripts/node_modules/tsx/dist/cjs/index.cjs:1:1250)
at Module.load (node:internal/modules/cjs/loader:1119:32)
at Module._load (node:internal/modules/cjs/loader:960:12)
at ModuleWrap.<anonymous> (node:internal/modules/esm/translators:169:29)
at ModuleJob.run (node:internal/modules/esm/module_job:194:25)
Node.js v18.18.0
However, these do work using per-product accessors:
import { initializeApp } from "firebase-admin/app"
import { getAuth } from "firebase-admin/auth"
import { getFirestore } from "firebase-admin/firestore"
const firebase = initializeApp()
const authx = getAuth(firebase)
const firestorex = getFirestore(firebase)