import { NgModule, Optional, SkipSelf } from '@angular/core'; import { CommonModule } from '@angular/common'; import { HttpClientModule } from '@angular/common/http'; @NgModule({ imports: [ CommonModule, HttpClientModule, ], declarations: [] }) export class CoreModule { constructor( @Optional() @SkipSelf() parentModule: CoreModule ) { if (parentModule) { throw new Error('CoreModule is already loaded. Import only in AppModule'); } } }