After Firebase deploy - Error: cannot find module - firebase

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.

Related

Firebase Deploy: Error: Could not detect language for functions at

I'm trying to deploy my firebase project, but Im getting the following error:
=== Deploying to 'my-proj'...
deploying firestore, functions, hosting
cloud.firestore: checking firestore.rules for compilation errors...
[W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
cloud.firestore: rules file firestore.rules compiled successfully
Error: Could not detect language for functions at
any thoughts?
In my case, I missed functions init:
firebase init functions
documentation
In my case I use firebase deploy --only hosting command
I can't tell what else is perhaps going wrong with your code, but I also had an error that looked like this part:
[W] undefined:undefined - Ruleset uses old version (version [1]). Please update to the latest version (version [2]).
Some of your firebase rules are written using version 1. You may need to go in and add
rules_version = '2';
to the top of your firebase rule set, specifically for Firebase Firestore. You can do this in the firebase console, or in the firestore.rules in your project - which may be a newly generated file in your project.
For anyone else who ends up here. I had setup firebase static hosting 1yr+ ago, and at that point in time hosting was a "function". Since then, hosting is now a distinct offering separate of functions.
You need to convert the previous "default" function (which 'was' hosting) to hosting offering.
Delete (or edit) firebase.json in the root directory of your firebase project.
Firebase init hosting -> This will create a new "public" folder.
Copy your previous functions/public folder to overwrite the new one.
Delete the previous functions folder altogether.
Now hosting is fixed and you can deploy again.
Firebase init functions -> This will create a new functions folder, and all of the boilerplate json and .js files.
The problem I was having is the functions folder had both hosting and functions stepping on each other within the functions directory. The "today" process puts hosting in a separate folder altogether.
Please update your rule to version 2 as the error message says.

Angular Universal + Firebase cloud functions deployment issue

I've been stuck on this issue for some time now.
My Angular project version is 9.0.3.
The #angular/fire version is 6.1.4
I have followed the guide here
The project builds and renders for the local Express server I have.
The problem occurs when I deploy the project to Firebase with a cloud function that will render the application.
Running the command ng deploy gives the below error
Error: ENOENT: no such file or directory, open '/home/teebo/Development/motf/dist/motif/browser/index.html'
This issue is linked to a reported issue here
I have investigated and found that in the project's dist folder, a index.original.html file is generated instead of index.html.
I have opened an issue here with no feedback from the maintainers.
If there is anything I am missing or there's something I can do to circumvent this issue, please share and any suggestions are appreciated.
Any suggestion, comment, anything.
I have found a way to circumvent this issue.
This is not a proper solution for the ng deploy issue but at least I can deploy the ssr function.
Because my dist folder is nested in another dist folder (Which does not include the browser build folder), that is why I was getting the error when running ng deploy. Below are steps I've followed to at least be able to deploy.
Run ng deploy (It will error out with the above error but will build the app and create a dist folder).
Copy the browser folder to the dist folder that does not have it (In my case I have copied it to a dist folder one level up).
Deploy the ssr function by running firebase deploy --only functions:ssr (You can change functions:ssr to whatever name you have named your function).
This worked for me;
It would save time to write an npm script to do all this but then; I am not sure if my firebase/universal config is wrong or there is a bug with #angular/fire.

Download or sync Firebase Functions to local environment

I am working on a Firebase project that currently uses several Cloud Functions.
The thing is that I want to download or sync the Cloud Functions to the local environment on my laptop.
I mean some command using firebase-tools or another like:
git clone [project name]
git fetch [something]
Usually, we create some cloud functions using the Firebase Console, and I would like to have these functions locally to edit these when needed and deploy them again.
I know that firebase-tools have these two commands, but it is only for configurations:
functions:config:clone [options]
functions:config:get [options]
There's no provided solution for automatically copying or synchronizing functions that have already been deployed. You can certain get the source code for deployed functions, but the Firebase CLI will not automate that process for you.
Ideally, you will want to manage all of your functions from the same source control and CLI in order to deal with them all consistent. Editing functions from the console is primarily a convenience, not a proper deployment mechanism.

No HTTPS functions found. Use firebase functions:shell

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.

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