【问题标题】:WARNING in Circular dependency detected: barrelsby Angular 10检测到循环依赖中的警告:来自 Angular 10 的桶
【发布时间】:2020-10-23 19:39:52
【问题描述】:

我在 Angular 10 中使用 bucketsby 时收到循环依赖警告。

Error: 
WARNING in Circular dependency detected:
src\app\core\components\components.module.ts -> src\app\core\components\header\header.component.ts -> src\app\state\index.ts -> src\app\core\components\components.module.ts

结构:

/component
  /header
    header.component.ts
    index.ts

index.ts

export * from './header.component';

component.module.ts

import { HeaderComponent } from './header';

@NgModule({
  imports: [],
  exports: [
    HeaderComponent,
  ],
  declarations: [
    HeaderComponent
  ]
})

index.ts

export * from './header/index';

【问题讨论】:

  • 编辑header.component.ts的内容并将其添加到您的问题中。
  • 有时你可以通过避免在某些时候从index.ts导入来打破循环依赖

标签: javascript angular typescript circular-dependency


【解决方案1】:

这只是一个警告,因此您绝对不需要修复它。警告告诉你圆圈在哪里:

  • 从标头导入模块
  • 从索引导入标头
  • 从模块索引导入

为了打破循环,我会避免从 index.html 导入。无论从索引导入哪个组件头,都从该组件文件夹导入它。

【讨论】:

  • 我已经尝试从组件导入,但它仍然抛出相同的。从 './header/header.component' 导入 { HeaderComponent };
猜你喜欢
  • 2021-11-13
  • 2018-05-08
  • 1970-01-01
  • 1970-01-01
  • 2018-11-20
  • 2020-10-02
  • 1970-01-01
  • 1970-01-01
  • 2019-09-19
相关资源
最近更新 更多