Firebase deploy functions - HTTP Error 403 - firebase

When trying to deploy my Firebase Functions (after switching computers) I get an error and can't deploy.
Error: HTTP Error: 403, Service Usage API has not been used in project 563584335869 before or it is disabled. Enable it by visiting https://console.developers.google.com/apis/api/serviceusage.googleapis.com/overview?project=563584335869 then retry. If you enabled this API recently, wait a few minutes for the action to propagate to our systems and retry.
I do not have a project with that ID and have switched between projects and it always gives me the exact same project ID. That link doesn't work for me, but when I put my project ID instead of 563584335869 then it works and the Service Usage API is enable.
Logging out and back in didn't solve the issue, neither did a firebase init.
Anybody know what could be causing this?

I think it may be related to firebase-tools 7.1.0. I back to 7.0.2 and it worked fine.
sudo npm uninstall firebase-tools
sudo npm i -g firebase-tools#7.0.2

firebaser here
There was indeed an issue introduced in the deployment of Cloud Functions with Firebase CLI version 7.1.0. The issue has now been fixed on our backend servers, and you should no longer encounter this issue.
If you continue to have problems, reach out to Firebase support for personalized help in troubleshooting.

I was getting the project 563584335869 error with Cloud Functions in the Firebase Emulators but not with Cloud Functions in the Firebase Cloud. In the Cloud I was getting a more common error about lack of credentials. I fixed both by adding Firebase Admin to the IAM service account for my Cloud Functions.

Related

Can't deploy Cloud Functions because of "Unhandled error cleaning up build images"

I've deployed hundreds of function and this is the first time I encounter this issue. Simply, it stops deploying function process, saying:
Unhandled error cleaning up build images. This could result in a small monthly bill if not corrected. You can attempt to delete these images by redeploying or you can delete them manually at https://console.cloud.google.com/gcr/images/[project-name]/us/gcf
The way I deploy is through Firebase CLI command: firebase deploy --only functions:nameOfFunction
Question is what are those images I have to delete? Why? How can I solve it?
Cloud Functions uses another product called Cloud Build to build the server images that actually get deployed. Those images are stored in Cloud Storage, and that storage is billed to your account.
Read more about it:
https://github.com/firebase/firebase-tools/issues/3404
https://krasimirtsonev.com/blog/article/firebase-gcp-saving-money
Watch:
https://www.youtube.com/watch?v=aHaI0jZ5rwM
You should be able to locate and delete the files manually in the Google Cloud console. But it sounds like there is a bug here with the files not being cleaned up automatically, so you contact Firebase support directly.
For me the issue appeared to be related to my GCF billing (https://console.cloud.google.com/billing)
I had to go to my billing account to see that my payment method was expired or something, and GCF had forecasted a monthly cost of $0.01, so deploying cloud functions was sort of locked until I updated the payment method. Then the deploy immediately worked again after updating it. The build-cleanup console warning also disappeared.
The error I was seeing in my function logs in firebase console was "billing account is not available". Which I found almost zero results for in Google. Which is why I'm posting it here.
For me, the issue was caused by a silly typo.
The error:
Functions deploy had errors with the following functions:
sendNotification(europe-west) i functions: cleaning up build files... ⚠ functions: Unhandled error cleaning up build images. This
could result in a small monthly bill if not corrected. You can attempt
to delete these images by redeploying or you can delete them manually
at...
The fix was choosing the right region.
The incorrect region:
exports.sendNotification = functions
.region("europe-west")...
The correct region:
exports.sendNotification = functions
.region("europe-west3")...
Go to https://console.cloud.google.com/apis/api/artifactregistry.googleapis.com/overview
select your project
enable Artifact Registry API
deploy functions again
In my experience going into Cloud Storage didn't solve the issue: there was no image there to be deleted.
I solved by changing the Node version, moving from 18 to 14.0.0
nvm install 14.0.0
nvm use 14.0.0
Check your Function logs, by either navigating through functions in the Firebase console or through https://console.cloud.google.com/logs
For me, the logs indicated that one of my typescript files had compiled under the wrong name and it was messing up the build.
Check the logs!
General troubleshooting tips given the variety of answers here:
if build is failing, read for other errors further up in the build output
add --debug to your CLI call, i.e.:
firebase deploy --only functions --debug
With --debug I found this in my output: "Permission 'artifactregistry.packages.delete' denied on resource"
My solution was to add Artifact Registry Administrator role to the IAM user deploying the function (in addition to Firebase Admin & Service Account User roles).

Can't login to Firebase with CLI

I have a weird problem with log in to Firebase using CLI. It's never happened before, so It's weird. I can log in using console.firebase.google.com, but not with CLI.
Because of that, I can't deploy updates to my service with firebase deploy --only hosting.
I tried to use: firebase login --reauth, remove .firebaserc, but with no success. The error message is always the same:
Firebase CLI Login Failed
The Firebase CLI login request was rejected or an error occurred. Please run a firebase login again or contact support if you continue to have difficulty logging in.
I thought that it's related to antivirus, because today I installed Bitdefender, and after that, I installed eset trial version. But I'm not sure it can be a problem, because I tried to stop eset - no success. Any idea?

Firebase deploy fails after adding second project

After adding a second project to my code using the command $ firebase use --add second-project, I get the error
There was an issue deploying your functions. Verify that your project has a Google App Engine instance setup at https://console.cloud.google.com/appengine and try again. If this issue persists, please contact support.
Error: HTTP Error: 404, Could not find Application "second-project".
when I run $ firebase deploy.
I have added separate targets and a web app through Firebase console for the second project.
What should I be checking to get rid of this error?
I just ran into this same exact issue as well. Leaving this here for anyone that runs into this issue in the future. What caused this error for me was a permissions error, when Firebase tried to access specific resources in Google Cloud such as Cloud Functions without the necessary IAM/service accounts in place.
This happens when you create a new Firebase project without setting the Default GCP resource location under Settings > General in the Firebase Console, which occurs when you create a new Firebase project without doing any additional setup. You can set this in the settings or this is also set when you follow the walk-through instructions for setting up services such as Firestore or Firebase Storage in the Firebase console.
Without this set, the <YOUR_FIREBASE_PROJECT_NAME>#appspot.gserviceaccount.com IAM/service account will not be created in Google Cloud (which is needed to create/access specific resources), therefore when you run firebase deploy, it will fail with the error you mentioned above.
You can also check why your firebase deploy is failing in the firebase-debug.log that is generated when running this command (that's how I found out the cause of this error). Though I think this file is deleted after the command finishes execution, so you'll have to pipe the output into a file or save it some other way.
TL;DR: Set Default GCP resource location, one way this can be done is in the Firebase Console under Settings > General.

Firebase deploy slow and getting a warning

When I try to run `Firebase deploy', it stucks at this line of code
i deploying functions
i functions: ensuring necessary APIs are enabled...
✔ functions: all necessary APIs are enabled
the firebase init and firebase login are doing fine but firebase deploy keeps stuck. My firebase version is 3.18.4 and im currently using ubuntu 17.10.
EDIT:
and after waiting for about an hour it diplays this line of code
FIREBASE WARNING: auth() was canceled: Auth token is expired.
Am I doing something wrong?. I am new to Firebase and I need some tips/ advice on why this happening
Here is a tip, that might help you. Give it a try and tell me if it resolves your issue.
Always use these commands instead of just firebase deploy
firebase deploy --only hosting
firebase deploy --only functions <<- use this in ur case. Also make sure your in the directory /functions of your project where you ran your firebase init
Sometimes Firebase services may be down, which would prevent you from deploying your code. If you can't deploy, check this site and see if at least all services are up and running: https://status.firebase.google.com/

Authentication Scope at firebase deploy

I recently submittet a "firebase deploy" command, and was notified that my deploy attempt had failed, due to insufficient authentication scope. What does "insufficient authentication scopes", mean?
I had a similar issue and I contacted the support who told me they are working on it.
They also provided a workaround that worked for me. Instead of calling firebase deploy to update everything, split the process and call:
firebase deploy --only hosting
firebase deploy --only database
For hosting, an other workaround is to deploy twice (the update actually works, only the 'Current' version is not updated to the latest), and then rollback the latest deploy, which will make the previous (identical) one current.

Resources