question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

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.

cc @cryptonikki @erakoviczoran

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:9 (3 by maintainers)

github_iconTop GitHub Comments

4reactions
milosmnscommented, Nov 2, 2022

Verified, the bug is gone if I simply downgrade axios to v0.27.2.

2reactions
taeoldcommented, Nov 2, 2022

@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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Legacy compat API of firebase-admin 11.x breaks Cloud ...
It looks like initialization of Firebase Admin fails on launch. This happens both with serve and deploy --only functions .
Read more >
Cloud Functions for Firebase - Google
Cloud Functions for Firebase is a serverless framework that lets you automatically run backend code in response to events triggered by Firebase features...
Read more >
Troubleshooting Cloud Functions - Google Cloud
By default this account is assigned the Cloud Functions cloudfunctions. ... This role is required for Cloud Pub/Sub, IAM, Cloud Storage and Firebase...
Read more >
How to use Firebase Cloud Functions with the new modular ...
In this project I use Firebase Functions. There I have upgraded to firebase-admin 11.0.0. But it seams it does not provide the new...
Read more >
How to use the firebase-functions.handler function in ... - Snyk
BitlyClient(config_1.default.bitlyAccessToken); // Initialize the Firebase Admin SDK admin.initializeApp(); logs.init(); exports.rtdburlshortener = functions.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found