firebase-tools
firebase-tools copied to clipboard
`firebase emulators:start` not working when not connected to the internet
The emulator works fine if I launch it while connected to the internet and then go offline, but not if I try to start it while disconnected from the internet.
I've found some references in other issues to the emulator working offline, but it is not clear from the documentation whether it is expected to work.
It seems to try to get the cli.json
file to do a version check. It would be ideal if this resulted in a warning rather than failing. Even if it worked for a day or two, if it is trying to avoid bad versions of the API ,it would be ideal for travel :)
user@machine-name functions % firebase --project=local-emulator emulators:start --only auth,functions,firestore
i emulators: Starting emulators: auth, functions, firestore
Error: Failed to make request to https://firebase-public.firebaseio.com/cli.json
⚠ emulators: It seems that you are running multiple instances of the emulator suite for project local-emulator. This may result in unexpected behavior.
⚠ Your requested "node" version "14" doesn't match your global version "16"
⚠ functions: Unable to fetch project Admin SDK configuration, Admin SDK behavior in Cloud Functions emulator may be incorrect.
Having trouble? Try firebase [command] --help
I think we could make the emulators work without internet - though as you've discovered, some bits and pieces of the configurations may be out of date or not available. This isn't something I can personally dedicate time to right now, but I think this could work.
Hi, thanks for filing this feature request! We are unable to promise any timeline for this, but if others also have this request, adding a +1 on this issue can help us prioritize adding this to the roadmap.
(Googler-only internal tracking bug: b/208891946)
+1. For my current dev environment, everything else works offline - except the emulators.
I put together a working temporary solution for my docker containers that allows the local computer to act as the https://firebase-public.firebaseio.com/cli.json host using NGINX and some self-signed certificates.
https://github.com/dereekb/dbx-components/commit/68321092395a01dd50ef6df57b02ca03839b91d7#diff-23f0ced0bdffb0a4b687d03d94e637a7bd0f60de6af348231efcb23ef260a805
It's not an ideal solution but the cli.json
file doesn't seem to have any particularly important information and the changes are localized to that docker container. I wouldn't try this directly on your machine since it effectively redirects all firebase-public.firebaseio.com
traffic to that NGINX container.
@bkendall @lisajian I just send out a pull request. Happy to work through any design feedback.
If you use a "demo-" prefix the hosting emulator will skip the call to prod for the config. I'm able to start the emulator suite offline this way.
Using a project ID without a demo prefix will still fail.
If you use a "demo-" prefix the hosting emulator will skip the call to prod for the config. I'm able to start the emulator suite offline this way.
Using a project ID without a demo prefix will still fail.
I confirm, it work like a charm, thanks 🙏
It was an "hidden" feature in the doc https://firebase.google.com/docs/emulator-suite/connect_firestore#choose_a_firebase_project
Project IDs for demo projects have the demo- prefix. ... Better offline support, since there is no need to access the internet to download your SDK configuration.
This works great for me too. To make this clear for anyone coming here and wanting a concrete example, assume that my proejct ID is my-project-name
. Then I do the following to start the emulators
firebase --project demo-my-project-name emulators:start
The --project flag overrides the normal project ID given in my .firebaserc
file.
This did lead to a disconnect between the project ID I connected to in my client and the one started by the emulators, which meant I didn't see my changes to the firestore database. To fix that, I made the following code.
import { FirebaseOptions } from 'firebase/app'
export const useEmulators = process.env.NODE_ENV === 'development'
const projectName = (useEmulators ? 'demo-' : '') + 'my-project-name'
export const options: FirebaseOptions = {
apiKey: '...',
authDomain: projectName + '.firebaseapp.com',
projectId: projectName,
storageBucket: projectName + '.appspot.com',
messagingSenderId: '...',
appId: '...',
measurementId: '...',
}
I have nore really comprehended how to set up the emulator on local (windows machine), I have followed every possible piece of code, up to the one for @Parakoos, none works. I am on a windows plaform, can someone provide a step by step to do this, all the documentations seems to be confusing, or not adding up.
I have nore really comprehended how to set up the emulator on local (windows machine), I have followed every possible piece of code, up to the one for @Parakoos, none works. I am on a windows plaform, can someone provide a step by step to do this, all the documentations seems to be confusing, or not adding up.
@bwerere just running this command on my side, i'm able to have a local version of emulators
npx firebase emulators:start --only firestore,auth,functions,storage --project demo-e2eprojectid
⚠️ After that you have to say to your app to use local version:
Here for my Cypress run in my package.json using env var
{
"cypress:open": "cross-env FIRESTORE_EMULATOR_HOST=localhost:8080 ng run app:cypress-open",
}
Or here for my AngularFire
import { USE_EMULATOR as FIRESTORE_EMULATOR } from '@angular/fire/firestore';
// ...
providers: [
{
provide: FIRESTORE_EMULATOR,
useValue: environment.production ? undefined : ['localhost', 8080],
}
// ...
],
And if you are still lock, feel free to ping me by DM on Twitter https://twitter.com/AurelienLoyer 🐦