Google Cloud Build & Firebase Deploy - "An unexpected error has occurred" - firebase

I'm using Google Cloud Build to do a deployment to Firebase Hosting when a commit is on master. I'm using the Firebase Cloud Builder, deployed to my project. I've checked permissions in the Cloud Console and Firebase access is enabled.
Everything seems to go well in generating the static HTML for hosting, but at the final build step it fails suddenly with this problem:
Error: An unexpected error has occurred.
Here is the step in my cloudbuild.yaml that fails:
- name: gcr.io/$PROJECT_ID/firebase
args: ['deploy', '--project', '$PROJECT_ID']
id: Deploy to Firebase

The last time that I installed the container was in October. The "An unexpected error has occurred" was solved by others by updating their version of the Firebase CLI. I had to do the same thing in my CD environment in order to get this to work.
Following these instructions in the README:
cd cloud-builders-community/firebase
gcloud builds submit --config cloudbuild.yaml .
The Firebase CLI version was reinstalled and published to my project. Then I was able to retry the build and it worked successfully.
This tripped me up for about an hour yesterday, and I thought it may be helpful to just have the answer documented somewhere.

Related

Where can I find firebase cloud function deploy logs? Path starts with /www-data-home/.npm/_logs/

I am getting an error message
Build failed: npm ERR! Cannot read property 'firebase-admin' of undefined\n\nnpm ERR!
A complete log of this run can be found in:\nnpm ERR!
/www-data-home/.npm/_logs/2022-11-23T04_36_44_234Z-debug.log; Error ID: beaf8772"
Where is this www-data-home location?
I was having the same error, updated package.json to use engine: 16, deployed again and then it worked (believe it forced updating all npm that could have been corrupted remotely).
As mentioned in this documentation on Viewing logs
Logs for Cloud Functions are viewable either in the Google Cloud
Console, Cloud Logging UI, or via the firebase command-line tool.
Using the Firebase CLI To view logs with the firebase tool, use the
functions:log command: firebase functions:log
To view logs for a specific function, provide the function name as an
argument:
firebase functions:log --only <FUNCTION_NAME> For the full range
of log viewing options, view the help for functions:log:
firebase help functions:log
You can view logs for Cloud Functions in the Cloud Logging UI using
filter as those resource types
resource.type="cloud_function"
Refer this npm docs on npm logging.
The npm CLI has various mechanisms for showing different levels of
information back to end-users for certain commands, configurations &
environments.
All logs are written to a debug log, with the path to that file
printed if the execution of a command fails.You can find the
npm-debug.log file in your .npm directory. To find your .npm
directory, use npm config get cache.
You can also check this stackoverflow thread

CICD on GCP for Firebase Functions failing due to "replace /workspace/.runtimeconfig.json?" error

I have CICD for cloud functions as some of the functions require token (collection deletion), my pipeline takes care of that.
Since last release, the cloud build is failing to deploy functions as it's expecting some key press which can't be done during cloud build. The actual log error says the following:
"replace /workspace/.runtimeconfig.json? [y]es, [n]o, [A]ll, [N]one, [r]ename: NULL"
Locally I am able to run the Cloud Functions with Node 14, but on GCP I'm not able to find a fix for GCP Cloud Build.
**Note: **
I'm using latest packages as of today. firebase-tools package: 9.4.0
There are similar questions for deploying functions locally but none of them work for me as it's during Cloud Build. I'm using the guide here: https://cloud.google.com/build/docs/deploying-builds/deploy-firebase
https://github.com/firebase/firebase-tools/issues/3120
Firebase Functions deploy requires keyboard input in GCP
Well the answers on other links mentioned above were correct indeed. What I didn't realize was that Docker image of node during build takes the latest automatically. Thus, now it was taking Node 15.xx version.
To fix this, just update Node version in the cloudbuild.yaml. For example following during npm install on GCP:
- name: node:14
entrypoint: npm
waitFor: ['-']
id: 'npm-install'
dir: 'functions'
args: ['install']

Firebase Deployment Error "Error: Functions did not deploy properly."

I have deployed Firebase functions in the past many times. For some reasons, recently (around 2-3 days) I am frequently getting error while deployment. I am using windows to release the code. When I tried with setting up the same project in my Linux system and Mac system the deployment works correctly. What may be the issue for the release from Windows environment.
The following is the issues getting while deployment.
! functions[payment(us-central1)]: Deployment error.
Function failed on loading user code. This is likely due to a bug in the user code. Error message: Error: please examine your function logs to see the error cause: https://cloud.google.com/functions/docs/monitoring/logging#viewing_logs. Additional troubleshooting documentation can be found at https://cloud.google.com/functions/docs/troubleshooting#logging. Please visit https://cloud.google.com/functions/docs/troubleshooting for in-depth troubleshooting documentation.
Functions deploy had errors with the following functions:
admin
cancellation
cost
createStripeCharge
customer
driver
driverLiveTracking
generalSettings
notification
order
payment
To try redeploying those functions, run:
firebase deploy --only "functions:admin,functions:cancellation,functions:cost,functions:createStripeCharge,functions:customer,functions:driver,functions:driverLiveTracking,functions:generalSettings,functions:notification,functions:order,functions:payment"
To continue deploying other features (such as database), run:
firebase deploy --except functions
Error: Functions did not deploy properly.
Following is the deployment command I am using for
"echo Deploying Functions && npm run lint && npm run build && firebase deploy --only functions"
Please share your knowledge over the issue.
Thanks.
I have resolved this issue. On building, I found that the node modules and lib functions are not replacing correctly with the new build. I have done a name changing previously and that are not reflecting in the new build.
Steps followed:
Removed node modules and lib files
Npm install
Npm run serve
And a new build is worked fine as well. I got the same issue using Jenkins build also. I just manually removed the same in server also.
You can find the issue by examining the actual logs. view them using this command
firebase functions:log
The specific issue will be visible there. I sometimes had error as simple as a missing packages in package.json

Firebase and Gitlab continuous integration pipeline failing

I am trying to hook up a simple static website to firebase hosting from Gitlab using their continuous integration tab. After downloading and installing firebase command line tools I am here:
stages:
- deploy
deploy-prod:
stage: deploy
only:
- master
script:
- firebase use <project-name> --token $FIREBASE_TOKEN
- firebase deploy --only hosting -m "Pipe $CI_PIPELINE_ID Build $CI_BUILD_ID" --token $FIREBASE_TOKEN
After that in firebase I deploy the site. However, gitlab then reports that the job is not deployed because
Error: firebase use must be run from a Firebase project directory.
Run firebase init to start a project directory in the current folder.
I dont understand the error, as I have in fact run firebase in the project director. Or is the error referring to the image thats in the yml file?
Either way, could someone please help me out? I've found a number of blog posts using CI in gitlab with firebase but I am stuck.
I got same issue and solved it by check folder structure
in my case:
/root/xx_project
firebase.json is in xx_project
so I need to cd xx_project

Changing target Firebase ID using firebase-tools CLI

At the command line...
When I run firebase deploy, I get the following error:
Error: The entered credentials were incorrect.
When I run firebase deploy --debug, I get the following (more detailed) error (and log) shown when you click here. (firebase-debug.log)
When I run firebase deploy --project good-project-id, I get the expected deployment behavior.
When I rerun firebase deploy and firebase deploy --debug I get the same errors already described.
How do I make the proper changes to eliminate the errors when running firebase deploy?
Notes:
I am running Mac OS/X Yosemite v10.10.5
I just ran the NPM installation procedure (via Homebrew) described here.
Look at the contents of your .firebaserc file in your project directory. You likely have a "default" project alias specified. Run firebase list and see if that project id shows up there as well (note it should be the project id, not the instance/subdomain name).
If it doesn't match, that's likely your issue. Another thing you can try is deleting the .firebaserc file and then running firebase use --add to create a new project alias.

Resources