Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

HMR t v6.1.0 RC3: Firestore Emulators Error: Precondition failed #2655

Closed
Meistercoach83 opened this issue Nov 15, 2020 · 4 comments
Closed

Comments

@Meistercoach83
Copy link
Contributor

Hey there! I have a problem with firebase / angularfire2 (latest rc) and the cloud emulators. If I add this
{ provide: USE_FIRESTORE_EMULATOR, useValue: environment.useEmulators ? ['localhost', 8080] : undefined },
to my app.module, the routing (with guards) is not working any longer with the error message "NavigationError(id: 2, url: '/setup', error: FirebaseError: [code=failed-precondition]: Firestore has already been started and its settings can no longer be changed. You can only modify settings before calling any other methods on a Firestore object.) platform-browser.js:66 " Can anyone help me with that?

Version info

Angular: 11.0.0
Firebase: 8.16.1
AngularFire: latest RC 6.1.0-rc.3
Other (e.g. Ionic/Cordova, Node, browser, operating system):
Angular CLI: 11.0.1
Node: 12.18.1
OS: win32 x64

@jornetsimon
Copy link

I'm getting this too.
AFAIK this bug was introduced in 6.1.0 RC3.
The important missing piece is that it only happens with HMR enabled (ng serve --hmr).

Stack trace indicates this has to do with redeclaring AngularFirestore :
Screen Shot 2020-11-16 at 08 31 49

You can reproduce by commenting any piece of code (except root styles) and let Webpack pick up the change.

@Meistercoach83 Maybe you could rename the issue with a more precise description

@Meistercoach83 Meistercoach83 changed the title Firestore Emulators Error HMR t v6.1.0 RC3: Firestore Emulators Error: Precondition failed Nov 16, 2020
@jamesdaniels
Copy link
Member

jamesdaniels commented Nov 16, 2020

hmr would make sense, as firebase has side effects and angularfire is for the most part side-effect free. e.g, AngularFirestore doesn't keep a global cache of it's instantiated instances. Instead when it's initialized it merrily tries to create and initialize a new firestore instance.

There's two work arounds here IMO, A) keep a global cache for instantiated firestore instances B) inspect the settings/options on an instantiated instance & check that they match the passed in settings, else try to apply and error out if it fails. The benefit of B would be better guard rails incase someone tries to mess with DI to change firestore settings without creating a second app & you'd get a helpful error if you changed the DI with hmr on. I'll investigate that option today.

jamesdaniels added a commit that referenced this issue Nov 17, 2020
#2661)

* Adding global instance caches to the modules, so they don't freak out when HMR is enabled (#2655). This takes on `globalThis` as a needed polyfill for many environments.
* If injected settings for modules are changed after they are initialized you will receive a warning and the prior instance will be returned (ignoring the changes), this is especially important for HMR. If HMR is detected there will be an additional warning suggesting they do a full reload to see the changes.
* Added a polyfill table and notes about why we version like we do
* Adding more convoluted stuff to my sample app to flex AngularFire
* Internal cleanup on AngularFireAnalytics
* AngularFireAnalytics will now wait for UserTrackingService to detect the user before sending the screen_view event, if UserTrackingService has been provided
* Adding a warning if the Auth Emulator is detected in conjunction with AngularFirestore and AngularFireDatabase as they will invalidate the emulated auth token before the dynamic import of `firebase/auth` is completed (#2656)
* Warn if we absorbed an error keeping Firestore persistence from enabling
* Logging sign_up and login events in UserTrackingService
* Adding credential observer to AngularFireAuth
@jamesdaniels
Copy link
Member

jamesdaniels commented Nov 17, 2020

This should be resolved in 6.1.0.rc-4.

@jamesdaniels
Copy link
Member

I added a globalThis cache of instantiated firebase SDK instances. It should ignore & warn if DI tokens change & will include an additional note if HMR is detected. Please report a new issue if you find any more problems with AngularFire and HMR, I've not had the chance to give it a spin.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants