Getting StaticInjectorError & NullInjectorError in Angular7 production build

Viewed 554

Hi I am developing an Angular Progressive Web Application (PWA) with Angular 7. After doing the production build with ng build --prod I am getting the following error while running:

ERROR Error: StaticInjectorError[e -> function(){}]: 
  StaticInjectorError(Platform: core)[e -> function(){}]: 
    NullInjectorError: No provider for function(){}!
    at e.get (main.c61af9b8ddfa2457805d.js:1)
    at main.c61af9b8ddfa2457805d.js:1
    at e (main.c61af9b8ddfa2457805d.js:1)
    at e.get (main.c61af9b8ddfa2457805d.js:1)
    at main.c61af9b8ddfa2457805d.js:1
    at e (main.c61af9b8ddfa2457805d.js:1)
    at e.get (main.c61af9b8ddfa2457805d.js:1)
    at Pv (main.c61af9b8ddfa2457805d.js:1)
    at main.c61af9b8ddfa2457805d.js:1
    at Iv (main.c61af9b8ddfa2457805d.js:1)

I am unable to trace the error to its actual cause or what might be causing it. Please help in resolving it.

app.module.ts

import { BrowserModule } from '@angular/platform-browser';
import { NgModule } from '@angular/core';
import { ReactiveFormsModule } from '@angular/forms';
import { StorageServiceModule } from 'angular-webstorage-service';
// Custom modules
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
import { LoggerService } from './common/services/logger.service';
import { Logger } from 'angular2-logger/core';
import { LoginComponent } from './components/login/login.component';
import { DashboardComponent } from './components/dashboard/dashboard.component';
import { NotfoundComponent } from './components/notfound/notfound.component';
import { FalDriverService } from './common/services/faldriver.service';
import { ApplicationSession } from './common/entities/application/application.session';
import { GlobalService } from './common/services/global.service';
import { SeedDataService } from './common/services/seeddata.service';
import { HeaderComponent } from './components/header/header.component';
import { HttpClientModule } from '@angular/common/http';
import { LoginGuardService } from './common/services/loginguard.service';
import { AppCacheService } from './common/services/appcache.service';
import { HttpService } from './common/services/http.service';
import { DatabaseService } from './common/services/database.service';

@NgModule({
  declarations: [
    AppComponent,
    LoginComponent,
    DashboardComponent,
    NotfoundComponent,
    HeaderComponent
  ],
  imports: [
    BrowserModule,
    AppRoutingModule,
    ReactiveFormsModule,
    HttpClientModule,
    StorageServiceModule,
    ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.production })
  ],
  providers: [

  ],
  bootstrap: [AppComponent]
})
export class AppModule { }

Earlier all my services are inside providers. I removed them following this particular answer: StaticInjectorError[e -> e]: NullInjectorError: No provider for e

2 Answers

Try adding this line

environment.production ? ServiceWorkerModule.register('/ngsw-worker.js') : [],
ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }),

I had this issue too, but with Angular 8.

You can help narrow it down to what providers are missing by running ng serve --prod locally on your development machine. Then you will be able to see the full error message.

Related