irregularly my firebase deployment get stuck at this log:
i functions: updating function [FUNCTION NAME]...
After canceling the deploy and retrying it throws the following error message:
⚠ functions: failed to update function resetBadgeCount
⚠ functions: HTTP Error: 400, An operation on function [FUNCTION NAME]
in region us-central1 in project [PROJECT NAME] is already in progress.
Please try again later.
So it seams like that the deploy got stuck and kept in the pipeline blocking further deploys. After a while it let me deploy the functions normally again.
But is there an explanation for this? Or maybe even a word around?
Go to Google cloud functions console and see if there is red exclamation mark against your function. Then select that particular function and try to delete. once it gets deleted from there, you can deploy again successfully. if it is showing spinner, then wait till it shows red mark.
Try this
You can fix the issue much easier by examining the actual logs using this command to open the log
firebase functions:log
The specific issue will be visible there. I sometimes even had errors as simple as a missing package in package.json
You can temporarily rename your function:
$ firebase deploy --only functions
...
i functions: deleting function onSameDataChanged...
i functions: creating function onSameDataChanged1...
...
✔ functions: all functions deployed successfully!
✔ Deploy complete!
Comment or cut your function
Deploy
Uncomment or paste back the function
Rename the function
Deploy
Rename the function back
Deploy
also you can wait a few minutes and you will get an error with {"code":10,"message":"ABORTED"}, then you can deploy again.
just copy your index.js to some where else and delete function form firebasa function console
firebase init -and overe write all file again
past index.js text again
deploy...
For me it was the node version. Turns out I had the 15.x on my machine and the 12.x on the server. Just updating it solved my upload issue
Make sure you've installed dependencies in the functions directory.
for more information about you function you can go to this page
Set your directory to your project directory \functions then run this command:
npm install -g firebase-tools
Related
I havae the following firebase cloud function codes and want to deploy to my project.
exports.bgTask = functions.region(Defs.SERVER_AREA)
.tasks.taskQueue({
retryConfig: {
maxAttempts: 5,
minBackoffSeconds: 60
},
rateLimits: {
maxConcurrentDispatches: 6
},
}).onDispatch(async (data) => {
});
Obviously, the above code just copied from firebase cloud function sample and it can be run under emulator, but when I tried to deploy to server and had no luck.
I tried to run firebase functions:log command and see the following error log.
So, it seems that Firebase cli cannot recognize the taskQueue property.
I googled a lot and had no luck. The following screen shot shows the corresponding library what I am using.
Anyone has any ideas on this?
Thanks in advance!
As mentioned by #Xavier, He managed to fix the issue by creating a new project and initialize Firebase function and deployed successfully by including the packages that are needed and run the command npm install --save firebase-functions#latest for the latest version of Firebase Functions.
I have a Firebase code project with Functions meant to be deployed to multiple Firebase projects over multiple regions.
I used to set the deployment region like this:
return functions
.region(process.env.REGION)
// ...
and used this command to deploy:
$ REGION=us-central1 firebase deploy --only functions
it worked like a charm until recently. Now it seems to completely ignore REGION=us-central1 even if I export it before I run firebase deploy.
EDIT 2022-06-13 - Possible solution
I changed the code to dump the contents of process.env to a file during deployment. This is what I got:
{
"FIREBASE_CONFIG": "{\"projectId\":\"REDACTED\",\"storageBucket\":\"REDACTED.appspot.com\",\"locationId\":\"us-central\"}",
"GCLOUD_PROJECT": "REDACTED",
"CLOUD_RUNTIME_CONFIG": "{REDACTED}",
"__CF_USER_TEXT_ENCODING": "REDACTED"
}
so definitely is not the same list of variables I have in my local environment.
I could use the locationId from FIREBASE_CONFIG to get the target location, or CLOUD_RUNTIME_CONFIG (it contains the dump of the functions .config() object, so I could set the target there).
I also believe that I could use the .env and .env.{project alias or ID} files and their contents would be available in process.env at deployment time.
As per Osvaldo López's suggestion, here are some other details:
Running on MacOS
No errors are reported
No recent changes to the CLI
Any input would be very welcome! Thanks.
I have a firebase function that is triggers on firestore doc OnCreate with failurePolicy set to true like so:
const webhookHandler = functions
.runWith({
failurePolicy: true,
memory: '512MB',
timeoutSeconds: 60,
}).firestore.document(`${COLLECTIONS.eventsQueue}/{event_queue_id}`)
.onCreate(async (snap, context) => {
//some code here...
})
Locally, using Firebase CLI i can deploy successfully, but requires I acknowledge that this function will retried on failure, do you still want to deploy? Yes/No.
once Yes is selected the function deploys successfully.
I'm using Github Actions to deploy the firebase functions automatically on PR merge. and Once i added the above function the github action deploy fails.
My assumption is that github action deploy is failing because the prompt.
My github deploy github action script does have --non-interactive and also tried with --force and it keeps failing.
Seems the --force does not enforce on this function deploy locally or in github deploy. Any suggestions to resolve this.
You can use the yes command included with most linux distros.
yes | firebase deploy ...
credit to #nVitus helped solve this.
the exact script that solves it:
yes | firebase deploy --only functions --force
I have created a group of Firebase Cloud Functions (v2) that are deployed in a region (europe-west1).
#index.ts
import * as apiV2 from './v2';
export const v2 = apiV2;
#v2.ts
export const addTextMessage = functions.region('europe-west1').onCall(
...
)
I want only to deploy the addTextMessage function.
I tried:
firebase deploy --only functions:v2-addTextMessage
# or
firebase deploy --only "functions:v2-addTextMessage(europe-west1)"
However the function is not deployed:
✔ functions: functions folder uploaded successfully
i functions: current functions in project: v2-addTextMessage(europe-west1)
⚠ functions: the following filters were specified but do not match any functions in the project: v2-addTextMessage(europe-west1)
What command should I use?
Try to replace the "-" by ".".
You should use :
firebase deploy --only functions:groupName.functionName
In your case :
firebase deploy --only functions:v2.addTextMessage
It's true that the CLI terminal log is misleading because if you've exceeded your deployment quota and the CLI detects that the name of your function is for instance v2-addTextMessage(europe-west-1), it will print a message suggesting you to use the command firebase deploy --only functions:v2-addTextMessage to deploy this function only, which doesn't work.
See the full Firebase CLI documentation here
You are using the correct command, however, you have not exported the addTextMessage function to your index.ts file, without that the deployment cannot find the funtion to deploy. You can export it by adding the following code to your index.ts:
export const v2-addTextMessage = apiV2.addTextMessage
Also, you cannot use the functions parameter and the function name as a String. So your command on this case would have to be:
firebase deploy --only functions:v2-addTextMessage
For Specifying region on deployment, as you already added to your code on the edited version of the question, you cannot do it on the FirebaseCLI command, thanks to #Doug Stevenson for pointing that out on the comment section.
Ideally, as you can see on this video, you would have to specify that in your cloud function code, before deployment by adding the following:
exports.v2-addTextMessage = functions
.region('europe-west1')
.storage.object().onFinalize((object) => { });
I am trying to follow this tutorial from Firebase Web Codelab, but I am facing a problem at step 5: after running the command firebase serve, I do not get the expected response
Listening at http://localhost:5000, but instead I get:
i functions: Preparing to emulate functions.
i hosting: Serving hosting files from: ./
+ hosting: Local server: http://localhost:5000
which is bad because functions are not being served, although ⚠ functions: Failed to emulate api is not prompted, it remains "preparing to emulate functions" ad infinitum.
More information: CLI Version: 3.18.4
Platform: win32
Node Version: v6.12.3 and I already tried going to ~/.config/configstore/ and deleting the #Google-Cloud folder in order to restart the whole process.
I'm pretty sure you are in the right track, the difference between the expected message (Listening at http://localhost:5000) and the message you get (hosting: Local server: http://localhost:5000) is because you are using the new version of the CLI (v3.18.4) but the codelab chapter is not updated to reflect the new change in the logging message.
You can see the difference in the source-code firebase-tools v2.2.1 where it displays
Listening at http://<HOST>:<PORT>
and in firebase-tools v3.18.4 it displays
hosting: Local server: http://<HOST>:<PORT>
And for the functions emulation, as you are in step5, you don't have yet functions, see functions in the codelab source code.