Error parsing triggers: Cannot find module 'firebase-admin/lib/database' - firebase

I was working on my firestore functions. It went fine until today's flutter upgrade. After upgrade "firebase deploy" is not working anymore:
$ firebase deploy
=== Deploying to 'project-id'...
i deploying database, storage, firestore, functions, hosting
Running command: npm --prefix "$RESOURCE_DIR" run lint
> functions# lint /Users/username/Desktop/projects/project/functions
> eslint .
✔ functions: Finished running predeploy script.
i database: checking rules syntax...
✔ database: rules syntax for database project-id is valid
i firebase.storage: checking storage.rules for compilation errors...
⚠ [W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
✔ firebase.storage: rules file storage.rules compiled successfully
i firestore: reading indexes from firestore.indexes.json...
i cloud.firestore: checking firestore.rules for compilation errors...
✔ cloud.firestore: rules file firestore.rules compiled successfully
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i storage: latest version of storage.rules already up to date, skipping upload...
✔ firestore: deployed indexes in firestore.indexes.json successfully
i firestore: latest version of firestore.rules already up to date, skipping upload...
i functions: preparing functions directory for uploading...
Error: Error parsing triggers: Cannot find module 'firebase-admin/lib/database'
Require stack:
- /Users/user/Desktop/projects/project/functions/src/profile.js
- /Users/user/Desktop/projects/project/functions/index.js
- /usr/local/lib/node_modules/firebase-tools/lib/triggerParser.js
Try running "npm install" in your functions directory before deploying.
Tried posts with similar topics on stackoverflow but they didn't work for me. Tried "npm install" from both project and functions directory, I beleive I have latest firebase-admin package, but still getting this error. Any hint is appreciated.

Do
flutter get packages
And tell me if it fixed or not thanks.

The reason was, one of the 'required' files inside 'functions' directory was updated during upgrade. This line was added:
const { admin } = require('firebase-admin/lib/database');
Commented this line and deploy is working fine for me now.

Related

Why will firebase CLI say deploy complete and not deploy a function?

I'm using the firebase-tools CLI to deploy firebase functions. I'm trying to deploy a function using firebase deploy --only functions:functionName.
This is in an existing project. The functions are located in /functions/index.js.
Up until a few hours ago, deploying worked fine. But now when trying to deploy a new function I get the following:
i deploying functions
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
+ functions: required API cloudbuild.googleapis.com is enabled
+ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing functions directory for uploading...
+ Deploy complete!
But it clearly does not even upload anything or deploy a function. Trying to deploy an existing function, I get The following functions are found in your project but do not exist in your local source code:
I'm a bit baffled as to how this seems to have "broken". Even looking at the git for the project there have been no changes to any config files or anything, other than writing a new function. I have not updated any packages since last deploying, and have tried the previous version of firebase-tools as well as the latest version.
Deploying a different function to a different project in the same manner is successful.
Turns out, I had created a file called functions.js in the project root directory (not /functions directory) and it appears firebase-tools was looking to that (empty) file for its functions, instead of the functions directory. Strange, and no kind of error message since I guess the file it thought it was looking for did exist.

Deployed my Next.JS app too firebase hosting but I do not see any functions in the firebase console

I followed this tutorial to deploy my Next.JS app to firebase:
https://itnext.io/deploying-next-js-app-to-firebase-functions-eb473791d79e
The output of my deploy script results in this:
i deploying functions, hosting
i functions: ensuring required API cloudfunctions.googleapis.com is enabled...
i functions: ensuring required API cloudbuild.googleapis.com is enabled...
✔ functions: required API cloudbuild.googleapis.com is enabled
✔ functions: required API cloudfunctions.googleapis.com is enabled
i functions: preparing . directory for uploading...
i hosting[hacks-life]: beginning deploy...
i hosting[hacks-life]: found 5 files in public
✔ hosting[hacks-life]: file upload complete
i hosting[hacks-life]: finalizing version...
✔ hosting[hacks-life]: version finalized
i hosting[hacks-life]: releasing new version...
✔ hosting[hacks-life]: release complete
✔ Deploy complete!
So when i go to the hosting url i get this:
Error: Forbidden Your client does not have permission to get URL
/nextjs-server/ from this server.
So i was thinking maybe there is an issue with my function not being deployed even though it seems to have been from the script output.
Any ideas?

Firebase does not deploy updated version

I am building an "actions on google" application with firebase hosting the node.js back-end.
First deployment was successful and provided a webhook which works fine.
After updating my .js files I run:
firebase deploy --only functions
and get the following output:
=== Deploying to 'monprogrammetele-c5169'...
i deploying functions
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
✔ Deploy complete!
Project Console: https://console.firebase.google.com/project/monprogrammetele-c5169/overview
Everything looks fine except that when I test with the simulator
https://console.actions.google.com/project/......
I still get the old version running....
The only difference I can see between the initial deploy and this one is that firebase is not providing a webhook link like it did the first time:
Function URL: https://us-central1-programmetele-82c89.cloudfunctions.net/teleProgram
I have assumed it is still the same.
The missing URL during deployment was fixed in version 3.16.0 of the CLI. Please upgrade it like this:
npm install -g firebase-tools
Issue was on my side, did some changes on index.js for local testing that were incompatible with firebase. I would suggest though that firebase is more explicit in its debugging messages.
Thanks for the help,
Thierry

Cloud Functions for Firebase - deploy error - Failed to initialize a region?

I'm in the process of uploading some Cloud Functions for Firebase via the Firebase CLI. I have my functions folder setup and everything is correct. :I actually use this exact functions folder in another project but for whatever reason in this particular project, when I run firebase deploy --only functions, I get this:
i deploying functions
i functions: ensuring necessary APIs are enabled...
i runtimeconfig: ensuring necessary APIs are enabled...
✔ runtimeconfig: all necessary APIs are enabled
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (972 B) for uploading
✔ functions: functions folder uploaded successfully
i starting release process (may take several minutes)...
i functions: updating function getUserByEmail...
⚠ functions[getUserByEmail]: Deploy Error: Failed to initialize a region
Functions deploy had errors. To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
Does anyone know what this error means?
Thanks in advance!

Firebase CLI deploy functions - Error: Failed to initialize a region

I'm having trouble doing firebase deploy --only functions for an app on Blaze plan.
I have the latest firebase-tools CLI (v 3.5.0).
I get the following error:
=== Deploying to 'myapp1234'...
i deploying functions
i functions: ensuring necessary APIs are enabled...
i runtimeconfig: ensuring necessary APIs are enabled...
✔ runtimeconfig: all necessary APIs are enabled
✔ functions: all necessary APIs are enabled
i functions: preparing functions directory for uploading...
i functions: packaged functions (1.29 KB) for uploading
✔ functions: functions folder uploaded successfully
i starting release process (may take several minutes)...
i functions: updating function myFunc...
⚠ functions[myFunc]: Deploy Error: Failed to initialize a region
Functions deploy had errors. To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
I've retried this every half hour for the past 12 hours, thinking there's an outage. The firebase status page shows all green.
Ok, here's what I found, a little weird:
firebase list shows all the firebase projects you have access to, BUT they are not already available (i.e. added as alias to your current folder project).
Even if the firebase-tools CLI allows you to do firebase deploy --project myproject1, if you do not have myproject1 declared in .firebaserc => it will fail with the weird region error above.
To fix this, I found that there are 2 options:
firebase use --add (will trigger an interactive list)
firebase use myproject1
=> and then firebase deploy --project myproject1 will work (with or without the optional --only functions)

Resources