Firebase CLI is not recognizing my project - firebase

Why can't anything be easy? I am trying to add push notifications from Firebase Cloud Messaging. When I run firebase init I get the following:
How do I get this to work? I have tried all the solutions I have read here but none of them have worked.

The CLI is recognizing your project, but the initialization is failing due to an error with Cloud Storage for Firebase.
Try going to the Storage section within your Firebase Console (here) and initialize Cloud Storage for Firebase first.
After you've chosen a location for your bucket try running your command again.

Related

GOOGLE_APPLICATION_CREDENTIALS for dummy Firebase project

I'm learning to set up Firebase Emulators correctly to work on my projects and I came up with a problem. I can setup the emulators and make them work locally, however, when trying to access firestore it seems to try to access the real Firestore Instance instead of the emulator.
Right now I'm initializing the app like this (in Cloud Functions)
admin.initializeApp();
const db = admin.firestore();
But when I'm running a function I'm getting:
Failed to initialize and load triggers. This shouldn't happen: Failed to read credentials from file GOOGLE_APPLICATION_CREDENTIALS.json: Error: ENOENT: no such file or directory, open 'GOOGLE_APPLICATION_CREDENTIALS.json'
The thing is that if I use the credentials I generated for my project it will work with the real Firestore instance instead of the emulator.
How should I make credentials for my emulated services?
If you are using Firebase Functions emulator as well then Admin SDK will connect to all the running emulators e.g. if only Auth emulator is running then it'll use the emulator and connect to production for other services like Firestore. You can explicitly set the FIRESTORE_EMULATOR_HOST environment variable and Admin SDKs will use the emulator then.
Checkout the documentation for more information.

Run firebase functions emulator on database without database emulator (towards production cloud instead)

I am having trouble running the firebase functions emulator towards a production database. I have a project which is not publicly released yet so I can run towards production with any negative effects.
My project uses only the realtime database, it does not use Firestore (so other questions on SO are not relevant) The documentation states "Cloud Firestore and Realtime Database triggers already have sufficient credentials, and do not require additional setup." so according to that, I shouldn't need any additional setup in order to point to the production database.
According to all of the documentation on Firebase, the project should run towards the real firebase database if I only start the functions emulator and do not start the database emulator. This warning seems to say so, too:
functions: The following emulators are not running, calls to these services from the Functions emulator will affect production: auth, firestore, database, hosting, pubsub
However, this is not what happens. Instead, I get the following error:
functions[onGlobalClientRequest]: function ignored because the database emulator does not exist or is not running.
I have read the firebase documentation and nothing is really mentioned other than setting credentials should not be needed (but I am setting credentials anyway using export GOOGLE_APPLICATION_CREDENTIALS="/path/to/credentials.json" before running the functions emulator.)
onGlobalClientRequest looks like this:
export const onGlobalClientRequest = functions.database
.ref( client_requests_key + "/{pushedid}")
.onCreate(
async (
snap: functions.database.DataSnapshot,
context: functions.EventContext,
) => {
///.... code here...
},
);
The locally emulated Firebase Functions will be able to write to the Prod database, but will not be able to get triggered by the production database.
Here is a SO answer from a Google employee that states the aforementioned.
Also, quoting from this other SO answer from another Google employee:
In general the rule with emulators:start is that we comprehensively emulate whatever is running. So for example if you're running the Functions and Database emulator, all writes from functions (through admin.database().... will be redirected to the Database emulator. But writes to Firestore (admin.firestore()...) will try and hit production because that emulator is not running.
Operations on a Realtime Database (RTDB) trigger the functions in the corresponding project. So the production RTDB triggers functions of your production project, and the emulated RTDB triggers emulated functions.
If you want to test functions triggered by RTDB operations locally with the emulator, you have to use the RTDB emulator as well. This is explained in the doc here.
If you only want to test HTTP callable functions, then you can use a remote RTDB.

How To Prevent Firebase Firestore Emulator From Clearing The Database At Exit?

I'm Planning To Use Firebase - Firestore Emulators For Handling Some Huge Amount Of Data That's Coming From A Websocket.
I just need to process the data locally in realtime.
Firestore Emulator Is A great choice since it has all the features I need. But the issue is it clears the database every time the Emulator is turned off. is there any config or settings that can change this behaviour?
if it is not possible. can somebody tell me any other Approach to use firestore locally? or any other alternative to firebase that I can use locally.
With the recent updates to Firebase Emulator, you use export the data when the emulator is running and import when it starts again.
To export the data
firebase emulators:export <export-directory>
To start and import the emulator
firebase emulators:start --import <export-directory>
I've managed this starting Firebase emulator with parameters to export data on exit and import existing one:
firebase emulators:start --import=exported-dev-data --export-on-exit=exported-dev-data
This way the emulator always export the data I've generated to folder exported-dev-data, and loads it back when starting again.
Currently you need to write code to populate the database during each run of the emulator.
If you would like to see different behavior, please file an issue on GitHub.

Unable to trigger firestore changes locally

I just started doing firebase and I need to do something when a new document is created but in functions and I setup cli and started locally but the function is not triggered.
while doing firebase init I chose firestore,functions,storage
after that did firebase login and firebase serve --only functions
and the server is up but whenever I add new document the function is not getting triggered?
You should be able to do that with firebase emulators:start. This starts emulators for Cloud Functions, Cloud Firestore, Realtime Database and Firebase Hosting. If that doesn't work, please share your code and I can have a look.
The docs may be useful too: https://firebase.google.com/docs/functions/local-emulator#run_the_emulator_suite

Error: HTTP error: 400, Project 'my_project' is not a Firestore enabled project

While I run the command firebase deploy I get this error:
Error: HTTP Error: 400, Project 'my_project' is not a Firestore enabled project.
Are you trying to use Cloud Firestore?
If so, visit the database section of the console and initialize Cloud Firestore
If not, remove the firestore.rules file locally
I figured it out myself. It was just an ignorance while using the firebase console. I just had to enable the firestore beta from the console itself, under Database.
If you’re not using Cloud Firestore, comment firestore in firebase.json
I had the same problem. The solution is this: Go to Firebase console and login there [Firebase console]. Here you will see your Recent projects. Go to your project e.g. “stepintothepresent” and then go to database at left side panel, then choose cloud firestore and then I selected the 2nd option.
After that I run firebase deploy from command prompt and the result is this
You can enable the REST APIs using below URL:
https://console.cloud.google.com/apis/library?project=
selected Cloud Firestore while initial firebase setup?
Just go to console and enable Cloud Firestore.
When prompted for once you can select test mode to start off and later change it to private.
I had to create a DB environment and it worked fine after that. I'm using the realtime DB, not Cloud storage so it shouldn't have stopped it, anyway, its fixed.
someone with another answer please.
Are you trying to use Cloud Firestore?
If so, visit the database section of the console and initialize Cloud Firestore
* Can you post the url please?
If not, remove the firestore.rules file locally
*Error: Error reading rules file firestore.rules

Resources