简体   繁体   English

角度错误:“是2个模块的声明的一部分(相同)”

[英]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! 未捕获的错误:DashboardComponent类型是2个模块的声明的一部分:DashboardModule和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. 只有一个名为DashboardModule的模块,并且DashboardComponent在此模块中仅声明和导出一次。

*Update *更新

Here is how the DashboardModule looks like 这是DashboardModule的样子

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 { }

In the meantime I found the bug: 在此期间,我发现了该错误:

It was Visual Studio code that decided to import the DashobardModule in a new style. 是Visual Studio代码决定以新样式导入DashobardModule。 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. 因此,有角度的想法将存在两个不同的DashboardModules并提出上面的错误。 Turns out Angular behaves totally correct but I have to find out why VS Code started to generate such a horrible mess... 事实证明Angular的行为完全正确,但是我必须找出为什么VS Code开始产生如此可怕的混乱……

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

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM