Empresas
Empleos
  • Sobre nosotros
  • Soluciones
    • Publicación de vacantes
      Publica tu vacante y recibe candidatos calificados en 48h.
    • Evaluación de candidatos
      500+ pruebas técnicas y psicológicas, más anti-fraude.
    • Headhunting
      Búsqueda ejecutiva a la medida de principio a fin.
    • Nómina + EOR
      Dispersión de nómina y EOR en más de 15 países de LATAM.
  • Precios
  • Empleos

0

1.7K
Vistas
Angular: 12 - Cannot access 'AppComponent' before initialization when doing "ng test"

When I'm trying to run "ng test", I just getting like the below:

Error message in UI by Karma v 6.3.4:
0 specs, 0 failures, randomized with seed 98146 Error during loading: Uncaught ReferenceError: Cannot access 'AppComponent' before initialization in http://localhost:9876/karma_webpack/main.js line 125

Error message in terminal:
An error was thrown in afterAll Uncaught ReferenceError: Cannot access 'AppComponent' before initialization ReferenceError: Cannot access 'AppComponent' before initialization at Module.AppComponent (http://localhost:9876/karma_webpack/main.js:125:61) at Module.36747 (http://localhost:9876/karma_webpack/webpack:/src/app/app.module.ts:16:5)

App.module TS FILE:

import { NgModule } from '@angular/core';
import { AppRoutingModule } from './app-routing.module';
import { AppComponent } from './app.component';
import { ServiceWorkerModule } from '@angular/service-worker';
import { environment } from '../environments/environment';
import { BrowserAnimationsModule } from '@angular/platform-browser/animations';
import { NgxUiLoaderModule } from 'ngx-ui-loader';
import { MatSnackBarModule } from '@angular/material/snack-bar';
import { HttpClientModule, HTTP_INTERCEPTORS } from '@angular/common/http';
import { HttpConfigInterceptor } from './auth/httpconfig.interceptor';
import { HeaderModule } from './shared/header/header.module';
import { RouterModule } from '@angular/router';

@NgModule({
  declarations: [
    AppComponent
  ],
  imports: [
    AppRoutingModule,
    BrowserAnimationsModule,
    ServiceWorkerModule.register('ngsw-worker.js', { enabled: environment.serviceWorker, registrationStrategy: 'registerImmediately' }),
    NgxUiLoaderModule,
    MatSnackBarModule,
    HttpClientModule,
    HeaderModule
  ],
  providers: [
    AppComponent,
    {
      provide: HTTP_INTERCEPTORS,
      useClass: HttpConfigInterceptor,
      multi: true
    }
  ],
  exports: [
    RouterModule
  ],
  bootstrap: [AppComponent]

})
export class AppModule { }

Is anyone knows how we can solve this?

over 4 years ago · Santiago Trujillo
2 Respuestas
Responde la pregunta

0

You should try to remove the AppComponent from the providers array. That can cause the error you are encountering.

over 4 years ago · Santiago Trujillo Denunciar

0

When I'm trying to run "ng test", I just getting like the below:

You have a test file ending with "spec.ts" which is mis-configured and that is causing this error. Check browser developer options and find out that meddling *spec.ts. After that you've two options:

  • delete that test file if you don't plan to test or
  • add required modules, providers, ... in your TestBed.configureTestingModule(...), so that spec.ts file is able to build successfully.
over 4 years ago · Santiago Trujillo Denunciar
Responde la pregunta
Encuentra empleos remotos

¡Descubre la nueva forma de encontrar empleo!

Top de empleos
Top categorías de empleo
Empresas
Publicar vacante Precios Comercial
Legal
Términos y condiciones Política de privacidad
© 2026 PeakU Inc. All Rights Reserved.
Andres GPT
Recomiéndame algunas ofertas
Necesito ayuda