Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Firebase Functions failing to deploy: npm ERR! Cannot read properties of undefined (reading '@google-cloud/functions-framework') #7909

Open
arnab opened this issue Nov 6, 2024 · 6 comments

Comments

@arnab
Copy link

arnab commented Nov 6, 2024

[REQUIRED] Environment info

firebase-tools: 13.24.1

Platform: MacOS (15.0.1)

$ uname -a
Darwin MacBookPro.lan 24.0.0 Darwin Kernel Version 24.0.0: Tue Sep 24 23:39:07 PDT 2024; root:xnu-11215.1.12~1/RELEASE_ARM64_T6000 arm64

[REQUIRED] Test case

I have had Firebase Functions (v1) running and deploying for a while. Today, I am seeing this error while deploying:

firebase deploy --only functions:myFuncName

✔  functions: Finished running predeploy script.
i  functions: preparing codebase default for deployment
i  functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i  functions: ensuring required API cloudbuild.googleapis.com is enabled...
i  artifactregistry: ensuring required API artifactregistry.googleapis.com is enabled...
✔  functions: required API cloudfunctions.googleapis.com is enabled
✔  functions: required API cloudbuild.googleapis.com is enabled
✔  artifactregistry: required API artifactregistry.googleapis.com is enabled
i  functions: Loading and analyzing source code for codebase default to determine what to deploy
Serving at port 8888

i  extensions: ensuring required API firebaseextensions.googleapis.com is enabled...
✔  extensions: required API firebaseextensions.googleapis.com is enabled
i  functions: preparing functions directory for uploading...
i  functions: packaged /Users/arnab/code/projects/directory-management-tools/functions (318.2 KB) for uploading
✔  functions: functions folder uploaded successfully
i  functions: updating Node.js 18 (1st Gen) function myFuncName(us-central1)...
Build failed: npm ERR! Cannot read properties of undefined (reading '@google-cloud/functions-framework')

npm ERR! A complete log of this run can be found in:
npm ERR!     /www-data-home/.npm/_logs/2024-11-06T00_04_48_347Z-debug.log; Error ID: f0ad4164

Functions deploy had errors with the following functions:
	myFuncName(us-central1)
i  functions: cleaning up build files...

Error: There was an error deploying functions

[REQUIRED] Steps to reproduce

I have a pretty large repository with 20+ functions (all v1) all running for over a year.

My Firebase-Functions dependencies:

    "firebase-admin": "^12.7.0",
    "firebase-functions": "^6.1.0",

I have also tried downgrading both these dependencies, as well as firebase-tools and keep seeing the same error.

[REQUIRED] Expected behavior

Not fail to deploy.

[REQUIRED] Actual behavior

See the above details. Essentially, the main error is:

Build failed: npm ERR! Cannot read properties of undefined (reading '@google-cloud/functions-framework')

npm ERR! A complete log of this run can be found in:
npm ERR!     /www-data-home/.npm/_logs/2024-11-06T00_04_48_347Z-debug.log; Error ID: f0ad4164
@arnab arnab added the type: bug label Nov 6, 2024
@arnab
Copy link
Author

arnab commented Nov 6, 2024

Also note that Firebase emulator is working fine, and executing these functions successfully (as expected).

I am only seeing this error while deploying the functions.

@arnab
Copy link
Author

arnab commented Nov 7, 2024

Couple more hints:

  • I tried with a 6 month old commit (and 6 month version of firebase-tools). It failed with the same error. I know that combination worked, because I have logs that show the function deployment back then with that version.
  • Note that I already have pre-deploy hooks and lint and build and it's not failing in that.
  • It seems to me like something server-side in Firebase Functions (Google Cloud Functions) has changed (maybe with the v2 migration) that requires google-cloud/functions-framework?

Now the good part:

Once I added it to my dependencies:

npm install --save @google-cloud/functions-framework

... it's working! With the older, or latest version of firebase-tools (and firebase-functions).

@arnab
Copy link
Author

arnab commented Nov 7, 2024

The Firebase Functions Getting Started Guide does not mention anything about google-cloud/functions-framework. If it is a required dependency, it should be mentioned there.

But perhaps, it should be a transitive dependency via the firebase-function package, but it doesn't appear to be right now?

I am assuming this is a recent change (something in the server-side of Google Cloud Functions deployments) that makes it necessary to have this dependency?

@aalej
Copy link
Contributor

aalej commented Nov 7, 2024

Hey @arnab, sorry for the delay, and thanks for the detailed report as well as for sharing your observations! I'm trying to reproduce this, but so far I haven't encountered any issues with deploying functions.

To help us reproduce the error, any chance you could share a minimal reproducible example or code snippets of the function you're trying to deploy?

In the meantime, I'll try asking our team to see if they may have an idea on what could be causing this or if there have been changes recently that could've affected this.

@arnab
Copy link
Author

arnab commented Nov 7, 2024

In my case, I have resolved it (see this comment above). Essentially, I have to explicitly add google-cloud/functions-framework as a dependency.

If that's not the case for all functions, and the Getting Started instructions are correct, I think this can be resolved (looks like it's something unique to my setup)?

@taeold
Copy link
Contributor

taeold commented Nov 7, 2024

Hi @arnab. Thanks for sharing an update and the workaround.

For context - google-cloud/functions-framework package is automatically installed when you deploy your functions to Google Cloud Functions. This should be transparent to the end user - I'm surprised you were having trouble with it.

I've reached out to internal team members to see if they are aware of the issue. Will keep you posted.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

3 participants