简体   繁体   English

在 Angular7 生产版本中获取 StaticInjectorError 和 NullInjectorError

[英]Getting StaticInjectorError & NullInjectorError in Angular7 production build

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:嗨,我正在使用 Angular 7 开发一个 Angular 渐进式 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)

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 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我按照这个特定的答案删除了它们: StaticInjectorError[e -> e]: NullInjectorError: No provider for e

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.我也有这个问题,但使用 Angular 8。

You can help narrow it down to what providers are missing by running ng serve --prod locally on your development machine.您可以通过在您的开发机器上本地运行ng serve --prod来帮助缩小提供者缺失的范围。 Then you will be able to see the full error message.然后您将能够看到完整的错误消息。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 Angular7:NullInjectorError:没有 FormGroup 的提供者 - Angular7: NullInjectorError: No provider for FormGroup Angular 测试 - NullInjectorError: StaticInjectorError(DynamicTestModule)[NgxPermissionsDirective -> NgxPermissionsService] - Angular tests - NullInjectorError: StaticInjectorError(DynamicTestModule)[NgxPermissionsDirective -> NgxPermissionsService] NullInjectorError: StaticInjectorError(Platform: core)[CompilerFactory] Angular - NullInjectorError: StaticInjectorError(Platform: core)[CompilerFactory] Angular Angular 9 - 错误:StaticInjectorError[Http]:StaticInjectorError[Http]:NullInjectorError:没有 Http 提供者 - Angular 9 - Error: StaticInjectorError[Http]: StaticInjectorError[Http]: NullInjectorError: No provider for Http 如何解决 Angular 8 解析器中的“NullInjectorError: StaticInjectorError” - How to troubleshoot 'NullInjectorError: StaticInjectorError' in Angular 8 resolver Angular 8:错误:未捕获(承诺):NullInjectorError:StaticInjectorError(AppModule) - Angular 8 : Error: Uncaught (in promise): NullInjectorError: StaticInjectorError(AppModule) Angular 测试 NullInjectorError:StaticInjectorError(DynamicTestModule)[UsersEffects -> Actions]: - Angular test NullInjectorError: StaticInjectorError(DynamicTestModule)[UsersEffects -> Actions]: 获取错误为“NullInjectorError:StaticInjectorError(AppModule)[ContactService -> HttpHeaders]” - Getting error as "NullInjectorError: StaticInjectorError(AppModule)[ContactService -> HttpHeaders]" NullInjectorError: StaticInjectorError(DynamicTestModule) 在 Angular 2 中测试时 - NullInjectorError: StaticInjectorError(DynamicTestModule) When Testing in Angular 2 NullInjectorError: StaticInjectorError(AppModule)[AppComponent -> GoogleTagManagerService]: Angular 8 - NullInjectorError: StaticInjectorError(AppModule)[AppComponent -> GoogleTagManagerService]: Angular 8
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM