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

Firestore enablePersistence(): “Error enabling offline persistence. Falling back to persistence disabled” #2404

Closed
kebarvid opened this issue Dec 5, 2019 · 3 comments · Fixed by #2407
Assignees
Milestone

Comments

@kebarvid
Copy link

kebarvid commented Dec 5, 2019

Describe your environment

  • Operating System version: All tested (Win10, OSX El capitain)
  • Browser version: Latest Chrome 6 Firefox
  • Firebase SDK version: 7.5.0
  • Firebase Product: Firestore

Describe the problem

I'm making a PWA app with Ionic 4 (angular) and Firebase Cloud Firestore as database. And it was working fine until just now when i wanted to enable offline persistance. Using AngularFire and the docs is not hard to follow. This is is how i enable it in my app-module.ts

@NgModule({
  declarations: [AppComponent],
  entryComponents: [],
  imports: [
    BrowserModule,
    IonicModule.forRoot(),
    AppRoutingModule,
    ComponentsModule,
    AngularFireModule.initializeApp(environment.firebaseConfig),
    AngularFirestoreModule.enablePersistence(), // <- Trying to enable here
    AngularFireAuthModule,
  ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
  ],
  providers: [
    { provide: RouteReuseStrategy, useClass: IonicRouteStrategy },
    GlobalService
  ],
  bootstrap: [AppComponent]
})
export class AppModule {}

When i run the app i get this warning in Chrome Developer Tools:

Error enabling offline persistence. Falling back to persistence disabled: TypeError: Cannot read property 'USE_MOCK_PERSISTENCE' of undefined

and a similar one in Firefox:

Error enabling offline persistence. Falling back to persistence disabled: TypeError: process.env is undefined

Steps to reproduce:

enable it in app.module.ts with:

AngularFirestoreModule.enablePersistence()

Relevant Code:

You can se the error live @ https://cubetrainer.nu

@kebarvid kebarvid changed the title Firestore enable: “Error enabling offline persistence. Falling back to persistence disabled” Firestore enablePersistence(): “Error enabling offline persistence. Falling back to persistence disabled” Dec 5, 2019
@thebrianchen thebrianchen self-assigned this Dec 5, 2019
@rommelpe
Copy link

rommelpe commented Dec 5, 2019

Thanks for reporting this issue, @kebarvid. I was able to encounter the same behavior using your live app. I'm trying to replicate this as well on my end using my new fresh app but wasn't able to replicate it. Can you help me reproduce the error? If you could provide a minimal repro of your app that I can run locally, that would be a great help for us to speed up the investigation. Thanks

@thebrianchen
Copy link

thebrianchen commented Dec 5, 2019

@kebarvid It seems like your app has overwritten the process global variable. The error you are getting stems from our check to use mock persistence (source code), because it seems that process is defined, but process.env is not.

I'll add an additional check of process.env !== undefined to the mock persistence check, which should stop the error from appearing, but to successfully enable persistence, you'll have to rename your global process to something else.

@kebarvid
Copy link
Author

kebarvid commented Dec 5, 2019

You are correct @thebrianchen . To make a database solution i was using earlier to work i did set a global variable called process. When i removed that everything works fine! Thanks for the help!

@hsubox76 hsubox76 added this to the 7.6.0 milestone Dec 12, 2019
@firebase firebase locked and limited conversation to collaborators Jan 5, 2020
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants