嗨,我正在用Angular 7开发一个Angular Progressive Web应用程序(PWA)。用ng build --prod
完成生产构建后,在运行时出现以下错误:
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
答案 0 :(得分:0)
尝试添加此行
environment.production ? ServiceWorkerModule.register('/ngsw-worker.js') : [],
ServiceWorkerModule.register('/ngsw-worker.js', { enabled: environment.production }),
答案 1 :(得分:0)
我也遇到了这个问题,但是使用Angular 8。
您可以通过运行以下命令,将其范围缩小到缺少哪些提供程序
ng serve --prod
在开发机器上本地。
然后您将能够看到完整的错误消息。