import { CommonModule } from '@angular/common';
import { HTTP_INTERCEPTORS, HttpClientModule } from '@angular/common/http';
import { APP_INITIALIZER, ModuleWithProviders, NgModule } from '@angular/core';
import { AngularFireAuthModule } from '@angular/fire/auth';
import { FormsModule, ReactiveFormsModule } from '@angular/forms';
import { MatButtonModule } from '@angular/material/button';
import { MatFormFieldModule } from '@angular/material/form-field';
import { MatInputModule } from '@angular/material/input';
import { MatSelectModule } from '@angular/material/select';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { RouterModule } from '@angular/router';
import { TranslateModule } from '@ngx-translate/core';
import { AuthInterceptor } from './interceptors/auth.interceptor';
import { ErrorInterceptor } from './interceptors/error.interceptor';
import { LoaderInterceptor } from './interceptors/loader.interceptor';
import { ApiConfig } from './models/api-config.model';
import { AuthGuard } from './service/auth.guard';
import { InitializerService, load } from './service/initializer.service';
/** Http interceptor providers in outside-in order */
const httpInterceptorProviders = [
{ provide: HTTP_INTERCEPTORS, useClass: AuthInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: ErrorInterceptor, multi: true },
{ provide: HTTP_INTERCEPTORS, useClass: LoaderInterceptor, multi: true }
];
@NgModule({
imports: [
CommonModule,
HttpClientModule,
AngularFireAuthModule,
FormsModule,
RouterModule,
ReactiveFormsModule,
TranslateModule.forRoot({
isolate: true
}),
MatButtonModule,
MatFormFieldModule,
MatInputModule,
MatSelectModule,
MatSnackBarModule
],
providers: [
ApiConfig,
AuthGuard,
{
provide: APP_INITIALIZER,
useFactory: load,
deps: [InitializerService],
multi: true
},
httpInterceptorProviders
]
})
export class LibCoreModule {
static forRoot(config: ApiConfig): ModuleWithProviders<LibCoreModule> {
return {
ngModule: LibCoreModule,
providers: [{ provide: ApiConfig, useValue: config }]
};
}
constructor() {}
}
Everything is compiling (without ivy enabled), but I got this error :
core.js:10756 Uncaught NullInjectorError: StaticInjectorError(AppModule)[InjectionToken angularfire2.app.options]:
StaticInjectorError(Platform: core)[InjectionToken angularfire2.app.options]:
NullInjectorError: No provider for InjectionToken angularfire2.app.options!
at NullInjector.get (http://localhost/vendor.js:48236:21)
at resolveToken (http://localhost/vendor.js:49192:20)
at tryResolveToken (http://localhost/vendor.js:49129:12)
at StaticInjector.get (http://localhost/vendor.js:49002:16)
at resolveToken (http://localhost/vendor.js:49192:20)
at tryResolveToken (http://localhost/vendor.js:49129:12)
at StaticInjector.get (http://localhost/vendor.js:49002:16)
at resolveNgModuleDep (http://localhost/vendor.js:63552:25)
at NgModuleRef_.get (http://localhost/vendor.js:64382:14)
at injectInjectorOnly (http://localhost/vendor.js:37859:29)
I've read plenty of stackoverflow, issues about this error, but nothing seems related to this problem, as it's always a lack of AngularFireModule.initializeApp(environment.firebase)
or bad usage of the lib.
AngularFireModule.initializeApp(environment.firebase)
inside LibCoreModule
in addition fo the one in AppModule
, or add it only on my lib. I always get the same error
ng add @angularfire/fire
and firebase init
, when I try to start the Firestore emulator (specifically - all the other ones appear to work fine), I get an error
Internal Error
and has the message Error: ShouldNotReachHere()
:D
I’m on an M1 Mac with Big Sur and using OpenJDK 64-bit 16.0.1
Without seeing your logs, can't tell if it's the same issue, but once I had a similar situation.
For me the solution was a combination of my Firebase version, JDK, and NodeJS. For example, I use the latest firebase with node 16 (lts) and JDK 11. -- Back when I encountered this I was using node 17 and an old version of firebase that didn't mesh