3

For my local development i installed the firebase emulators through firebase cli. Now i want my project to connect to the emulated firebase.

The connection to emulated Auth is already running fine.

I'm trying to use "useEmulator" on my firebase.firestore() My code is basically from the Docs (https://firebase.google.com/docs/emulator-suite/connect_firestore#web)

const db = firebase.firestore() const auth = firebase.auth() if (location.hostname === "localhost") { console.log('LOCAL') auth.useEmulator("http://localhost:9099") db.useEmulator("localhost", 8080) } 

I get this error Uncaught TypeError: s.useEmulator is not a function On this line: db.useEmulator("localhost", 8080)

What point did i miss? Thanks for help!

2 Answers 2

2

I got this hints on slacks firebase community:

Making sure your SDK version supports "useEmulator" (https://firebase.google.com/support/release-notes/js) or use this code for older versions:

 FirebaseService.db.settings({ host: 'localhost:8080', ssl: false, experimentalForceLongPolling: true, }) 
Sign up to request clarification or add additional context in comments.

2 Comments

Hey thanks so much. It might be useful to include a link to the docs for the usage of useEmulator. I can't seem to find any documentation on npmjs.com/package/firebase-admin or firebase.google.com/docs/admin/setup
@nkhil: I'm on firebase-admin 13.0.2, and get the same error, that db.useEmulator is not a function. Trying to use the "new" modular connectFirestoreEmulator is another shot in the dark, as 'firebase-admin/firestore' doesn't export that symbol, and attempting import { connectFirestoreEmulator } from 'firebase-admin/lib' fails with Uncaught Error: [ERR_PACKAGE_PATH_NOT_EXPORTED] Package subpath './lib' is not defined for types by "exports" in ...firebase-admin/13.0.2/package.json'.
0

If your project is a Node.js script running on your machine, the connection to Firestore should be made as explained at https://firebase.google.com/docs/firestore/quickstart#initialize -> Node.js -> Initialize on your own server, and telling Firebase to use the emulator should be done by setting the environment variable FIRESTORE_EMULATOR_HOST to 127.0.0.1:8080:

import { initializeApp, cert } from 'firebase-admin/app'; import { getFirestore } from 'firebase-admin/firestore'; const serviceAccount = '/path/to/service-account-key.json'; process.env['FIRESTORE_EMULATOR_HOST'] = '127.0.0.1:8080'; // Deno.env.set('FIRESTORE_EMULATOR_HOST', '127.0.0.1:8080'); initializeApp({ credential: cert(serviceAccount), }); const db = getFirestore(); 

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.