Firebase firestore not working with Angular 10 and SSR or prerender

Viewed 425

When i try to build a new project with angular 10, just adding import of the AngularFireModule from @angular/fire/firestore module is failing to build as a prerender or with a build:ssr command.

 "dependencies": {
"@angular/animations": "~10.0.2",
"@angular/common": "~10.0.2",
"@angular/compiler": "~10.0.2",
"@angular/core": "~10.0.2",
"@angular/fire": "^6.0.2",
"@angular/forms": "~10.0.2",
"@angular/platform-browser": "~10.0.2",
"@angular/platform-browser-dynamic": "~10.0.2",
"@angular/platform-server": "~10.0.2",
"@angular/router": "~10.0.2",
"@nguniversal/express-engine": "^10.0.1",
"express": "^4.15.2",
"firebase": "^7.16.0",
"rxjs": "~6.5.5",
"tslib": "^2.0.0",
"zone.js": "~0.10.3"

In the app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';

import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';

import { AngularFireModule } from '@angular/fire';
import { AngularFirestoreModule } from '@angular/fire/firestore';
import { AngularFireStorageModule } from '@angular/fire/storage';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { AboutComponent } from './about/about.component';
import { environment } from 'src/environments/environment';

@NgModule({
  declarations: [AppComponent, AboutComponent],
  imports: [
    BrowserModule.withServerTransition({ appId: 'serverApp' }),
    AppRoutingModule,
    AngularFireModule.initializeApp(environment.firebaseConfig),
    AngularFireAuthModule, 
    AngularFireStorageModule, 
    //this module failed to build
    //   AngularFirestoreModule, 
  ],
  providers: [],
  bootstrap: [AppComponent],
})

The error message :

ERROR in ./node_modules/@grpc/grpc-js/build/src/channel-credentials.js Module not found: Error: Can't resolve 'google-auth-library' in 'C:........\monApp\node_modules@grpc\grpc-js\build\src'

Seems like if there is a probleme in grpc module with angular 10...

1 Answers

I hope you've found a solution since you asked this question.

What I did when facing the same issue? Just install the package google-auth-library :

npm install google-auth-library --save

and then, it should be OK.

PS: I don't know the root cause of this issue but I know this workaround works.

Related