在 Angular7 生产构建中获取 StaticInjectorError 和 NullInjectorError

Getting StaticInjectorError & NullInjectorError in Angular7 production build

您好,我正在使用 Angular 7 开发一个 Angular 渐进式 Web 应用程序 (PWA)。在使用 ng build --prod 进行生产构建后,我在 [=25] 时收到以下错误=]:

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)

我无法追查错误的实际原因或可能导致错误的原因。请帮忙解决。

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 { }

早些时候我所有的服务都在提供商内部。我按照这个特定的答案删除了它们:StaticInjectorError[e -> e]: NullInjectorError: No provider for e

尝试添加这一行

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

我也有这个问题,但是 Angular 8.

您可以通过 运行 帮助将范围缩小到缺少的提供商 ng serve --prod 在您的本地开发机器上。 然后您将能够看到完整的错误消息。