I have a watcher in my Firebase project that automatically compiles and restarts the emulator whenever I change my code. It's nice except I think because of some race conditions I get a new firestore-debug.log or asidfhusudf.log file every time I save my code. How can I disable the log files or at least change the location where they are made?
firestore-debug.log is present in the same folder as firebase.json. You can see it in the directory you ran the command which will have a log of all the requests.
You are using typescript for functions so you can refer to the documentation on how function logs works for Typescript projects :
During firebase deploy, your project's index.ts is transpiled to index.js, meaning that the Cloud Functions log will output line numbers from the index.js file and not the code you wrote. To make it easier for you to find the corresponding paths and line numbers in index.ts, firebase deploy creates
functions/lib/index.js.map. You can use this source map in your preferred IDE or via a node module.
How debug output is stored in the firestore-debug.log is mentioned in the Documentation :
A basic debug function that prints Security Rules language objects, variables and statement results as they are being evaluated by the Security Rules engine.The outputs of debug are written to firestore-debug.log.
The debug function can only be called inside Rules conditions.debug function blocks are only executed by the Security Rules engine in the Firestore emulator, part of the Firebase Emulator Suite. The debug function has no effect in production.Debug logfile entries are prepended by a string identifying the Rules language data type of the log output (for example, string_value, map_value).Calls to debug can be nested.Currently, the debug feature does not support the concept of logging levels (for example, INFO, WARN, ERROR).
You can also refer to the stackoverflow case where Kiana and Daniel have provided a brief explanation on how logs older than 1 month got disabled automatically.
You can see it directly within the Firebase console. When trying to choose the timestamp for the logs, logs older than 1 month are disabled, which means are
automatically deleted.
You can refer to the documentation for getting an understanding of how Query language is used to filter logs in the Emulator suite UI.
Currently, there's no way to change the location since it's hard coded: https://github.com/firebase/firebase-tools/blob/c0f7acc80e8c4c2d174f97c5c41d6114e192fd23/src/emulator/downloadableEmulators.ts#L205
Related
Similar question to
How do you setup local environment variables for Cloud Functions for Firebase, but specifically looking how to setup environment variables that differ between development and production.
For example,
Say I would typically have:
.env
REACT_APP_DOMAIN: https://foo-bar.web.app/
.env.development
REACT_APP_DOMAIN: http://localhost:3000/
How would one create a similar setup for Firebase Cloud Functions?
I have an answer to my own question, though I don't think it's optimal.
In the Firebase's local-emulator documentation, they have this section:
Set up functions configuration (optional)
If you're using custom functions configuration variables, first run the command to get your custom config (run this within the functions directory) in your local environment:
firebase functions:config:get > .runtimeconfig.json
If using Windows PowerShell, replace the above with:
firebase functions:config:get | ac .runtimeconfig.json
Though poorly explained, this is just creating a json file .runtimeconfig.json, which contains your firebase config variables. The variables in this file are then used by the Firebase emulator, in place of what is stored in Firestore. This is better explained in this github repo ticket.
Now knowing this, .runtimeconfig.json can be used in a similar manner that .env.development is. Instead of using the command they suggest, you can just manually update it as you need (or use their command to pull down your firebase variables and then modify them as needed).
You access/use those local variables in the exact same way you would normally access Firebase variables, functions.config().foo.bar.
When deployed, they'll reference your variables as set on Firebase. When in development (through firebase emulator), they'll reference what you have in .runtimeconfig.json.
Hello I am following this tutorial in order to do push notifications to multiple devices at once in Expo React Native using Firebase's cloud functions. The push tokens are stored in my RealTime-Database, but when I attempt to integrate this step after running firebase login and firebase init, I updated my index.js file to contain this code. After saving this file, I attempt to do firebase deploy and I get 70 errors. I tried to deploy it from my app directory, and didnt work, and I tried to do it from my functions directory and that didn't work. I deleted my node_modules and package-lock, and I tried to rerun expo again and clearing my npm cache. Nothing worked. I already had my firebase app initialized somewhere else, could that be the reason why? But my App itself still works, so I am not getting an error saying that the Firebase app is being initialized twice. I really dont know what else do to. Is the ESLint causing all of these errors? Should I run firebase init again without adding ESLint? Please let me know. My errors are below.
When deploying your code, by default, your code is linted using a tool called ESLint.
The "errors" you see are eslint complaining about trivial things like missing semicolons at the end of a line, using ' instead of ", improperly indented code, among other things. If you ever don't understand what a rule is trying to do, you can visit https://eslint.org/docs/rules/{rule-name} (such as https://eslint.org/docs/rules/semi).
As shown in the error message, you can use eslint . --fix to automatically fix most of these. Just enter into your functions directory and execute eslint . --fix.
Most IDEs have a keyboard shortcut for automatically formatting your code to your rules. In VSCode for example, this shortcut is Alt+Shift+F.
Everytime I deploy a function, I have the annoyance that I need to answer the question:
The following functions are found in your project but do not exist in your local source code
with "No".
I have the following structure of my functions. I have a folder with the Typescript functions and then a different folder with the Javascript functions. They are in separate folders, because I am too dumb to get it to work in the same folder.
I initially created both folders using the Firebase CLI and choosing Typescript and Javascript respectively.
I am aware of the --force operator, but I think it will force "Yes" and I don't want the functions to be deleted.
As detailed in the documentation:
You could only target the specific functions you want to deploy, like:
$ firebase deploy --only functions:function1,functions:function2
Or you could group your Cloud Functions into export groups in your index.js/index.ts files.
Grouping functions allows you to deploy multiple functions using a
single command.
See the same doc for more detail.
And yes, the --force operator bypasses the confirmation prompt, but it is the confirmation prompt for deletion, not for deployment (the --force operator is to be used with functions:delete). Therefore it will not help in your case.
After adding a second project to my code using the command $ firebase use --add second-project, I get the error
There was an issue deploying your functions. Verify that your project has a Google App Engine instance setup at https://console.cloud.google.com/appengine and try again. If this issue persists, please contact support.
Error: HTTP Error: 404, Could not find Application "second-project".
when I run $ firebase deploy.
I have added separate targets and a web app through Firebase console for the second project.
What should I be checking to get rid of this error?
I just ran into this same exact issue as well. Leaving this here for anyone that runs into this issue in the future. What caused this error for me was a permissions error, when Firebase tried to access specific resources in Google Cloud such as Cloud Functions without the necessary IAM/service accounts in place.
This happens when you create a new Firebase project without setting the Default GCP resource location under Settings > General in the Firebase Console, which occurs when you create a new Firebase project without doing any additional setup. You can set this in the settings or this is also set when you follow the walk-through instructions for setting up services such as Firestore or Firebase Storage in the Firebase console.
Without this set, the <YOUR_FIREBASE_PROJECT_NAME>#appspot.gserviceaccount.com IAM/service account will not be created in Google Cloud (which is needed to create/access specific resources), therefore when you run firebase deploy, it will fail with the error you mentioned above.
You can also check why your firebase deploy is failing in the firebase-debug.log that is generated when running this command (that's how I found out the cause of this error). Though I think this file is deleted after the command finishes execution, so you'll have to pipe the output into a file or save it some other way.
TL;DR: Set Default GCP resource location, one way this can be done is in the Firebase Console under Settings > General.
I have noticed a strange behaviour in FireStore Cloud Functions that if try to break my code up into separate files, I start to get this error:
info: Worker for app closed due to file changes.
I just created a simple express server and hosted it in a cloud function and was emulating it locally as described here.
https://www.youtube.com/watch?v=LOeioOKUKI8&t=244s
I even wrote tests for the same. Everything was working fine until I split the source code of my express app into individual routes (contained in separate .js files).
The only thing that message means is that the emulator noticed when a code file changed, and performed a hot reload of that code. Note that it's just an "info" level message, not an error and not even a warning.
If your project is not working the way you expect, then edit your question with the symptoms you're observing, along with the code.