How to error the ng build command when circular dependencies detected
Asked Answered
E

1

7

I'm using Angular 9 and I would like my builds to to fail whenever the circular dependency is detected in the build target.

When I was using Angular 6 and below, I was just adding a Circular Dependency Webkack plugin (https://www.npmjs.com/package/circular-dependency-plugin) to my webpack config and it worked fine. However, in Angular 9, I do not have the access to the wepack config of the builder that is used to build my target. I don't want to use a custom:webpack builder.

Do you know how it can be achieved? I'm aware of the showCircularDependencies key in angular.json file but it is just there to turn the warnings on and off.

Evanne answered 26/9, 2020 at 15:31 Comment(0)
L
3

The Angular built-in Circular Dependency webpack plugin is deprecated in Angular 12 and will be removed in the future. The recommended method to detect circular dependencies is to use either a lint rule or other external tooling. ESlint has https://github.com/benmosher/eslint-plugin-import/blob/master/docs/rules/no-cycle.md

EDIT:

The ESlint rule is slow, perhaps not surprisingly since ESlint is designed for linting a file at a time and circular dependency checking is all about global information.

We use https://github.com/pahen/madge which is fast and works well.

Lungwort answered 24/5, 2021 at 12:22 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.