Connect to firestore emulator with admin SDK requires supplying the project-id
See original GitHub issueEdit: Summary of the discussion below:
- The firebase admin SDK must init with some project-id, but it doesn’t have to be a real one.
- Meanwhile, if you also want to visualize the db using the emulator UI, or if you’re using the function emulator at the same time, then the emulator must start with the same project-id as the admin SDK. This can be achieved with
firebase --project=some_project_id emulators:start
. Without the flag, the emulator will use the project id in your.firebaserc
, and create a different instance of db running parallel with the admin SDK’s instance.
===========
Original issue:
I found that when I have a firestore running on local emulator, and I want to directly access it with a script using the admin SDK, I need to supply the project-id to the admin SDK, which I believe is not the intended behavior.
I use the nodejs firebase-admin
package, not sure if the bug is theirs.
[REQUIRED] Environment info
firebase-tools: 8.10.0 npm firebase-admin package 9.1.1
Platform: Windows
[REQUIRED] Test case
see below
[REQUIRED] Steps to reproduce
- have the firestore emulator running
- create a
test.js
locally:
const admin = require('firebase-admin');
admin.initializeApp();
admin.firestore().collection('foo').add({ a: 1 });
- run it:
$ FIRESTORE_EMULATOR_HOST="localhost:8080" node test.js
[REQUIRED] Expected behavior
should see a document created in the emulator firestore UI
[REQUIRED] Actual behavior
Error: Unable to detect a Project Id in the current environment.
To fix this, I need to supply the project id to the admin SDK:
admin.initializeApp({ projectId: 'my-project-id' }); // now works
But I believe it’s not the intended behavior.
Issue Analytics
- State:
- Created 3 years ago
- Reactions:3
- Comments:18 (8 by maintainers)
Top Results From Across the Web
Connect your app to the Cloud Firestore Emulator - Firebase
If you want your Admin SDK code to connect to a shared emulator running in another environment, you will need to specify the...
Read more >connecting to firestore emulator from java admin sdk
The Firebase Admin SDKs automatically connect to the Cloud Firestore emulator when the FIRESTORE_EMULATOR_HOST environment variable is set:.
Read more >Testing apps locally with the emulator | Cloud Pub/Sub ...
The string does not need to represent a real Google Cloud project because the Pub/Sub emulator runs locally. gcloud beta emulators pubsub start...
Read more >Building a REST API with Firebase cloud functions, TypeScript ...
However, to be able to use Firebase functions, you'll need to upgrade your billing plan to the Blaze Pay as you go. We...
Read more >firebase instance id not found | The Search Engine You Control
firebase/firebase-toolsConnect to firestore emulator with admin SDK requires supplying ... To fix this, I need to supply the project id to the admin...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
With the following environment variables:
The following initialization seemed to allow the admin SDK to use the firestore emulator but it only allowed partial use of the auth emulator (calls to admin.auth().listUsers() returned an empty array despite there being at least one emulated user):
Currently using: firebase-tools: v9.4.0 npm firebase-admin package v9.5.0
@RicardoAratani we are working on a plan to make it much more obvious when you have a project ID mismatch and also make it easier to set things up!