When running the ng build --prod command, I encountered an error message that is causing some confusion:
The error states: Type SiteSecurity in "PATH"/siteSecurity.component.ts belongs to the declarations of 2 modules: SiteSecurityModule in "PATH"/siteSecurity.module.ts and SiteSecurityModule in "PATH"/siteSecurity.Module.ts!
This issue seems to indicate that my component is declared by two different modules, even though they are supposed to be the same.
Here is a snippet of the code involved:
siteSecurity.routing.ts
import { ModuleWithProviders } from '@angular/core';
import { RouterModule } from '@angular/router';
import { SiteSecurity } from './siteSecurity.component';
import { AuthGuard } from '../../../../../ReusableServices/AuthGuard';
export const SiteSecurityRouting: ModuleWithProviders = RouterModule.forChild([
{path: 'Datahub/Admin/Auth/SiteSecurity', component: SiteSecurity, canActivate: [AuthGuard]}
]);
siteSecurity.module.ts
import { NgModule } from '@angular/core';
import { FormsModule } from '@angular/forms';
import { BrowserModule } from '@angular/platform-browser';
import { SharedModule } from '../../../../../ReusableComponents/SharedModule';
import { SiteSecurity } from './siteSecurity.component';
import { SiteSecurityRouting } from './SiteSecurity.routing';
import { SiteSecurityService } from './siteSecurity.service';
@NgModule({
imports: [BrowserModule, SiteSecurityRouting, SharedModule, FormsModule],
declarations: [SiteSecurity],
providers: [SiteSecurityService]
})
export class SiteSecurityModule {
}
It appears that SiteSecurityModule is only imported into a parent module without any other references or imports elsewhere.
I suspect that the dual declaration of SiteSecurity in both the routing file and module file might be causing this conflict. However, removing it from either location results in errors. Has anyone encountered a similar problem before? What could be causing this issue?
My @angular/cli version is 6.2.4