Legacy compat API of firebase-admin 11.x breaks Cloud Functions for Firebase
See original GitHub issue[READ] Step 1: Are you in the right place?
I think so, yes.
[REQUIRED] Step 2: Describe your environment
See my previous report on Firebase Functions for details about my environment. Since then, I have updated my TS version to 4.6.4
, which fixed the errors I initially had with Admin SDK. But now I have a fresh set of errors.
- Operating System version: GH Actions image + macOS Monterey 12.5.1
- Firebase Product: database, functions
- Firebase SDK version: 11 (see more)
- Node.js version: 16 (see more)
- NPM version: 8 (see more)
The problem I’m reporting started happening after I updated Admin from 10.3.0
to 11.2.0
.
[REQUIRED] Step 3: Describe the problem
Steps to reproduce:
It looks like initialization of Firebase Admin fails on launch. This happens both with serve
and deploy --only functions
. TSC and Lint pass fine without any issues.
Here’s the console output with --debug
:
[2022-10-27T11:19:49.312Z] Building nodejs source
[2022-10-27T11:19:49.312Z] Analyzing nodejs backend spec
[2022-10-27T11:19:49.319Z] Could not find functions.yaml. Must use http discovery
[2022-10-27T11:19:49.450Z] Serving at port 9007
[2022-10-27T11:19:49.568Z] Got response from /__/functions.yaml Failed to generate manifest from function source: TypeError: Cannot read properties of undefined (reading 'create')
[2022-10-27T11:19:49.570Z] Failed to parse functions.yamlincomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 1, column 60:
... from function source: TypeError: Cannot read properties of unde ...
^ {"name":"YAMLException","reason":"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line","mark":{"name":null,"buffer":"Failed to generate manifest from function source: TypeError: Cannot read properties of undefined (reading 'create')\n\u0000","position":59,"line":0,"column":59},"message":"incomplete explicit mapping pair; a key node is missed; or followed by a non-tabulated empty line at line 1, column 60:\n ... from function source: TypeError: Cannot read properties of unde ... \n ^"}
[2022-10-27T11:19:49.583Z] shutdown requested via /__/quitquitquit
⬢ functions: Failed to load function definition from source: FirebaseError: Failed to load function definition from source: Failed to generate manifest from function source: TypeError: Cannot read properties of undefined (reading 'create') {"metadata":{"emulator":{"name":"functions"},"message":"Failed to load function definition from source: FirebaseError: Failed to load function definition from source: Failed to generate manifest from function source: TypeError: Cannot read properties of undefined (reading 'create')"}}
Relevant Code:
This is how I initialize the SDK now:
import * as functions from "firebase-functions";
import * as firebaseAdmin from "firebase-admin";
firebaseAdmin.initializeApp();
...
In another file I also have the following, but I don’t think my run ever reaches that stage to require the file to run.
import * as firebaseAdmin from "firebase-admin";
private static database = firebaseAdmin.database();
...
What have I tried:
- Googling, StackOverflowing, etc.
- This advice, even though the official documentation does not reflect it. It doesn’t fix the issue for me
- Reverting back to v10, which works but is not a solution to this problem
Priority
From my POV it’s high priority because the functions won’t launch, but not urgent. I can give more code/information if needed.
Issue Analytics
- State:
- Created a year ago
- Comments:9 (3 by maintainers)
Verified, the bug is gone if I simply downgrade
axios
tov0.27.2
.@milosmns Thanks for sharing your updates! Looks like we can close the issue for now - I’ll reach out to admin sdk to see if breaking
const { initializeApp } = require("firebase-admin")
was intentional in v11.