No HTTPS functions found. Use firebase functions:shell - firebase

I've been trying all day to get my functions to run locally but I don't know why it keeps saying I have no functions. I'm using typescript, so I ran tsc in the functions folder, then ran sudo firebase serve --only functions, but I get this error:
i functions: No HTTPS functions found.
Use firebase functions:shell if you would like to emulate other types of functions.
Edit: I tried serving the function without sudo but I get permission issues:

Make sure you have nothing running on the same port that the Firebase function emulator is trying to run on, in my case I had a Docker container running on port 5000. Once I stopped it and started the Firebase function emulator it served the function correctly.

Ok, I don't know why it worked, but I just restarted VSCode (because it had an update) and everything works now.

Related

Firebase emulator for Cloud Functions not updating the code

I'm deploying the following cloud function using firebase deploy --only functions :
export const testFunction = functions.https.onCall((data, context) => {
return {"data": "hello"};
});
and when call it from the client app using the code
var testFunction = firebase.functions().httpsCallable("testFunction");
testFunction().then((result) => {
// Read result of the Cloud Function.
this.data = result.data;
});
it works as expected.
Now, I want to continue developing the function testing it on the local emulator so, following the documentation, I added this line to the web app code (before the function)
firebase.functions().useEmulator("localhost", 5001); // for local simulator
and I run the local emulator with:
firebase emulators:start --only functions
If I run the client app now, I correctly see the call going through the local emulator instead of the remote cloud function.
Problem: If modify the code the local function doesn't get updated. I need to run firebase deploy again in order to see the change in the response. How can I just deploy locally?
This stackoverflow solves the issue.
Solution in short:
After every change in your code, run npm run build to recomplie the code.
To auto-compile for every change in your code.
Change "build": "tsc" to "build": "tsc -w" in your package.json
file, and run the emulator in an another terminal window.
You can use the functions shell as described in this documentation here in order to deploy, run and test functions locally. I find the documentation quite confusing, as it only mentions how to use .sh scripts to test locally.
firebase functions:shell
Note that if you use the shell, you don't need to run the emulators separately; the shell will run them for you. The shell will automatically update based on changes to the index.js functions file, but if you're using TypeScript you may have to rebuild after you make changes. This is typically done by going into the functions directory and running npm run build. You can also automate this as well, according to this answer, but I haven't tried this approach yet.

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.

Firebase commandline to list functions from GCP firebase

I have 100ds of functions deployed to firebase and I would like to know if I can list the remote functions on my machine using the firebase command line tools.
I want to see the list of functions deployed.
What I am trying to solve is:
Batch deploy functions to avoid deployment limit.
Deployment error when function deleted/renamed locally and then deploying whole functions.
Thanks!
I got the exact answer from Google support.
Currently, Firebase CLI doesn’t have any command to list deployed functions, whereas “gcloud functions list” CLI from Cloud SDK shows the list instead.
More details found here
While it doesn't seem to be documented here, you can list all deployed Cloud Functions when you have firebase-tools installed with firebase functions:list. The command is also mentioned in firebase --help.
Verified with firebase-tools version 10.5.0
At the time of writing this answer, there is no CLI command that allows listing all the deployed functions for your project. The available commands can be found here: https://firebase.google.com/docs/cli/#commands
However, note that you can list the deployed functions in the Google Cloud console (not the Firebase one) by opening: https://console.cloud.google.com/functions/list?project=your_project_name

After Firebase deploy - Error: cannot find module

Running a Node.js function in the local Firebase server does not result in the error below, but when I do firebase deploy and try to run the same function on the deployed server I get this error in the Firebase Functions log (in the web Firebase console):
Error: Cannot find module '#google-cloud/speech'
What have I missed? (I can run some other functions on the deployed server, but I am new to this and have no idea if I have done something different, or if there is something different about this npm module.)
Cloud Functions will only install the modules that you've declared as dependencies in your package.json (and their dependencies) in the functions folder. If the module doesn't show up there, you won't be able to access it directly from your code. Be sure to run #google-cloud/speech from your functions folder, so that you can use it both during development an when deployed.

Cloud Functions deployment failiure from Firebase

I seem to be unable to deploy Google Cloud Functions successfully.
I have created a project on Google Cloud Platform and then proceeded to link it to Firebase via the Firebase console. I select ADD PROJECT and Add Firebase to an existing project. Everything seems to link.
When I try to deploy a cloud function (the simple helloWorld that comes with installing firebase-tools) I keep getting deployment errors. This also happens when trying to deploy functions from Google Cloud Functions dashboard as well.
The error is something aboud setting up the environment.
After ttrying to rename the function to something else, I seem to have luck with deploying but then the function but there is a communication error Function load error: Error: cannot communicate with function.
I am unable to deploy functions on two of my projects, and firebase has been acting very strangely in the last few days, so can somebody please tell me if I am doing something wrong or is it a Firebase glitch
Maybe because there is an outage starting from early this morning. Check status here: https://status.firebase.google.com

Resources