Domenic
Domenic

Reputation: 738

Angular Error: "is part of the declarations of 2 modules (same)"

Today a very strange error occured:

Uncaught Error: Type DashboardComponent is part of the declarations of 2 modules: DashboardModule and DashboardModule!

That doesn't make any sense to me. There is only one module called DashboardModule and the DashboardComponent is declared and exported only once in this module.

*Update

Here is how the DashboardModule looks like

import { NgModule } from "@angular/core";
import { CommonModule } from "@angular/common";
import { FormsModule } from "@angular/forms";
import { NgbModule } from "@ng-bootstrap/ng-bootstrap";
import { TranslateModule } from "@ngx-translate/core";

import { TypeaheadModule } from "root/shared/typeahead/typeahead.module";
import { AppFormsModule } from "root/shared/forms/forms.module";

import { DynamicComponentService } from "./dynamicComponent.service";
import { DashboardComponent } from "./dashboard.component";
import { DashboardWidgetComponent } from "./widget.component";
import { ModalConfigComponent } from "./modalConfig.component";

import { DashboardService } from "./dashboard.service";

@NgModule({
    imports: [
        CommonModule,
        FormsModule,
        NgbModule,
        TranslateModule,
        TypeaheadModule,
        AppFormsModule],
    exports: [
        DashboardComponent,
        DashboardWidgetComponent,
        ModalConfigComponent],
    declarations: [
        DashboardComponent,
        DashboardWidgetComponent,
        ModalConfigComponent],
    providers: [
        DynamicComponentService,
        DashboardService],
    entryComponents: [
        ModalConfigComponent]
})
export class DashboardModule { }

Upvotes: 1

Views: 299

Answers (1)

Domenic
Domenic

Reputation: 738

In the meantime I found the bug:

It was Visual Studio code that decided to import the DashobardModule in a new style. Instead of

import { DashboardModule } from "root/shared/dashboard/dashboard.module";

it started to generate this code

import { DashboardModule } from "root/shared/dashboard/dashboard.module.js";

On other parts of the code the old way still existed. So, angular thought there would exist two different DashboardModules and brought up the error above. Turns out Angular behaves totally correct but I have to find out why VS Code started to generate such a horrible mess...

Upvotes: 1

Related Questions