Firebase functions change names when deploying - firebase

I have been working with functions for a while, recently I made a function called "unPublishStore" in my index.js file.
When calling firebase deploy --only functions every thing runs flawlessly, but the function's name gets changed, where in the cmd it shows the following:
and in the firebase's functions list the name is also changed:

This feels very much like a typo error.
Please check you index file, ensure the definition name on the left side:
exports.functionNameToDeploy = functionYouWrote;
The functionNameToDeploy will exactly be the name shown in cloud instead of the functionYouWrote
Probably you can search globally in your project to see if there is a function called upPublishStore?

Related

Firebase deploy failed even without changing the function from onCallable to onRequest

Error: [functionName(us-central1)] Changing from a callable function to an HTTPS function is not allowed. Please delete your function and create a new one instead.
Any advice and insight is appreciated.
Which version of Firebase CLI (firebase --version) are you using? Last night I updated firebase-tools package to 10.3.0 and functions deployment started giving me the error you mention. I downgraded to 10.2.2 and functions deployment started working as before.
Update:
Firebase team confirmed there is an issue with 10.3.0 firebase-tools. They are working on a fix:
https://github.com/firebase/firebase-tools/issues/4307
Solution 01:
I think the main problem lies inside whether you are using a valid way to use .env file. Since I just recently have this kind of error. If you do use the .env file inside the structure of your folder, then
You need to declare the path to .env file in all files which uses process.env.VARIABLE_NAME. Example way is like this:
require("dotenv").config({path: "../.env"});
After that try to delete all existing Cloud Functions in Google Cloud Console
Try deploy again: firebase deploy --only functions
I added a path to the .env file, since I checked Firebase Cloud Function Logs and it gave me error for all Cloud Functions which uses process.env.VARIABLE_NAME. This .env file must be located inside the root project and placed inside folder functions/. Give it a try. Hope it works.
Solution no. 2:
You should check if there is a variable or function which doesn't give return value, like example below:
const key = async () => {
const response = await pk.accessSecret("PRIVATEKEY");
return response;
};
I forgot to add a return value from the variable const key. Therefore I get so many errors like you do in all of my functions. And that errors cause firebase cli to state"
Changing from a callable function to an HTTPS function is not allowed.
Please delete your function and create a new one instead.
this happened to me as well. npm i -g firebase-tools#latest did the trick.

Deploying over an existing Firebase Function without deleting it first fails silently or leads to "Internal" error when called

Our Firebase Functions have been working fine. However, we noticed that recently when we deploy a new version of a function over an existing one, e.g. "firebase deploy --only functions:PurchaseShopItem", the deploy will report success. But the PurchaseShopItem function will simply be the old version. We can even look at the source code and see that it's still the old version.
The only work around is to manually delete the function either from the CLI or from Firebase Functions console.
Related problem: When bulk deploying (for example, "firebase deploy --only functions") some of our functions get stuck in a state where they are present in the Functions Console, but trying to call them leads to an immediate "internal" error return code to the client. No log appears in the Firebase Functions Logs. The fix is the same: If we delete the function first then redeploy, it starts working.
Even deleting a function by removing it from index.js and redeploying doesn't seem to work (the existing function just fails with "internal" and no more information.) Only deleting the function from Console or explicitly from CLI seems to work to replace it.
Has anyone seen this where you must manually delete a function in Firebase Functions Console before you can deploy over it? Are there any work arounds? Are we doing something wrong?
It can take some time for a function to fully deploy after the CLI finishes. That's expected, and the total time can vary. You're not doing anything wrong.

structure firebase functions into multiple runtimes

I've been using firebase ecosystem for over 2 years but as it google lacks decent documentation i often come here to ask very basic things that we should learn right after "hello world".
When using firebase functions i try to modularize it to keep it readable and easy to maintain. the way i managed to do it was by having an "index" file and multiple subfiles which contains the logic for complex functions...
although it works very well, my index file is getting super long since i'm having more and more functions and it also needs to deal with some configuration for each of those specific functions...
i was messing around firebase dashboard https://console.cloud.google.com/functions/list? and i found that is possible to create a new function over this online form... when doing it the firebase backeend somehow create a new "runtime" for this function. I mean each function created by this form has its own "index.js" "package.json"
how can i do this without need to create every function from this form?
how can i simple code a new function ecosystem, deploy it using firebase cli and have this separeted structure for it?
All Cloud Functions are logically isolated from each other at all times at runtime. While they might share some common code at deployment, they don't share anything else.
The Firebase CLI requires that all your functions be defined in a single entrypoint, which is your index.js. That is just how it works. If you don't like that, you can deploy functions individually using gcloud, but you will not be able to use the firebase-functions module to declare and implement your function. gcloud uses different conventions.
If you want to continue to deploy with the Firebase CLI, you can add the new function to your index.js. It can be deployed separately from your other functions using the --only argument. For example, if your new function is called "fn":
firebase deploy --only functions:fn
This will deploy just fn and none of the other functions defined in your index. You can read about this and more options in the Firebase CLI documentation for deploying functions.
If you abosolutely do not want to have all your functions in a single index.js, you can split the definitions among multiple files, and require or import them into the main index.js. It's up to you how you want to organize your source file, using the facilities provided by nodejs and JavaScript.

How to update in firebase cloud function source code

I have a firebase project which has cloud functions, i don't have the original source code and i want to update in the source code.
i tried to follow the documentation of firebase but it create new folder, i don't know how to get the current source code to update it then deploy it.
also i get the source code using "https://console.cloud.google.com/functions" but can't know how to deploy the code after update on it.
Here is the solution which i follow:
Go to the Cloud Console > Cloud Functions list.
Select any of the functions.
Inside the function's detail, click on the Source tab.
Then at the bottom, you'll see the "Download.zip" button.
Then you can make changes,i.e add new function >> add the code for that function and update the index.js (append your work on it to avoid deleting the old functions) then follow the firebase documentation to deploy only one function

How do you un-deploy Cloud Functions for Firebase?

I was experimenting with Cloud Functions for Firebase and deployed one of the samples in the functions-samples repo and linked it to an existing project using firebase use --add.
Since I was just playing around, these files were not added to my version control, and I no longer have access to the machine this was done on. I would like to build on this function or create new ones, but I am unsure how to either 1) modify and re-deploy over the original function or 2) un-use --add and start fresh. I see the function in my firebase console but no 'delete' or 'remove' button and have read through the CLI docs looking for clues to no avail.
Thanks for adding functions to the firebase 'stack.' Any guidance is much appreciated.
Functions get deleted when they aren't present during a firebase deploy. Most commonly that'd be because because you removed the function from your index.js, but if you've removed the whole functions directory that'll work too.
To continue work on a function for which you don't have the source anymore, the easiest is to start fresh. The function(s) you deploy will replace the ones you deployed previously.
Alternatively, if you're partial to using the Google Cloud Console instead of the Firebase Console, the Cloud Console will show you the code for the currently-deployed function, so you can copy-paste it onto your local machine.
The Cloud Console also has a 'delete' button for every function, and even a web editor. Be aware when editing functions from the Cloud Console though: your next firebase deploy will overwrite any changes.
To delete a function explicitly use the following command:
$ firebase functions:delete myFunction
Replace myFunction with your function name. For detailed info. follow this link: https://firebase.google.com/docs/functions/manage-functions
Go to Google Cloud Console Cloud Functions and select project, then select the function you want to undeploy or delete. Select it and click delete.
To delete/undeploy a single function, you can delete the code for your function and then run the following in command line:
firebase deploy --only functions:YourFunctionName
Replace YourFunctionName with the name of your function
In the case that you are working on other functions that you are not ready to deploy or do not want to deploy all of your functions for any reason, then the code above can be handy. This also feels a bit safer since you're not redeploying everything :)
Now you can simply delete a function from the function dashboard as follows. Click on the three dots mark of relevant function in the right side corner.

Resources