New cyclical dependency errors in library with compilationMode: partial
See original GitHub issueWhich @angular/* package(s) are the source of the bug?
compiler
Is this a regression?
Yes
Description
We are upgrading our Angular library to v13 with partial compilation mode and we’re seeing new errors for cyclical dependencies coming from the component templates that are not thrown view engine compiler. I’m providing a link to a PR which shows the errors in the CI runs (both GitHub actions and Azure Pipelines).
Please provide a link to a minimal reproduction of the bug
https://github.com/IgniteUI/igniteui-angular/pull/10043
Please provide the exception or error you saw
projects/igniteui-angular/src/lib/splitter/splitter-bar/splitter-bar.component.ts:13:1
13 @Component({
~~~~~~~~~~~~
14 selector: 'igx-splitter-bar',
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
...
249 }
~~~~~
250 }
~
The component 'IgxSplitBarComponent' is used in the template but importing it would create a cycle: D:/GitHub/igniteui-angular/projects/igniteui-angular/src/lib/splitter/splitter.component.ts -> D:/GitHub/igniteui-angular/projects/igniteui-angular/src/lib/splitter/splitter-bar/splitter-bar.component.ts -> D:/GitHub/igniteui-angular/projects/igniteui-angular/src/lib/splitter/splitter.component.ts
Please provide the environment you discovered this bug in
_ _ ____ _ ___
/ \ _ __ __ _ _ _| | __ _ _ __ / ___| | |_ _|
/ △ \ | '_ \ / _` | | | | |/ _` | '__| | | | | | |
/ ___ \| | | | (_| | |_| | | (_| | | | |___| |___ | |
/_/ \_\_| |_|\__, |\__,_|_|\__,_|_| \____|_____|___|
|___/
Angular CLI: 13.0.0-next.1
Node: 16.4.2 (Unsupported)
Package Manager: npm 6.14.11
OS: win32 x64
Angular: 13.0.0-next.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, platform-browser, platform-browser-dynamic
... router
Package Version
---------------------------------------------------------
@angular-devkit/architect 0.1300.0-next.1
@angular-devkit/build-angular 13.0.0-next.1
@angular-devkit/core 13.0.0-next.1
@angular-devkit/schematics 13.0.0-next.1
@angular/cli 13.0.0-next.1
@schematics/angular 13.0.0-next.1
ng-packagr 12.2.0
rxjs 6.6.7
typescript 4.3.5
Anything else?
The exception that I’ve provided is just one of many that we’re getting in the library. We used to have cyclical dependency warnings that were all fixed. All of these errors are brand new after switching to partial ivy compilation mode.
Issue Analytics
- State:
- Created 2 years ago
- Reactions:3
- Comments:5 (4 by maintainers)
Top Results From Across the Web
NG3003: Angular 12 Circular Dependency in library - Ivy ...
I have to mention again here that this problem (NG3003) Only happens in Angular libraries with partial compilationMode.
Read more >NG3003: Import cycles would need to be created to compile ...
So when building libraries using the "compilationMode": "partial" setting, ... require a cyclic import will cause this NG3003 compiler error to be raised....
Read more >Help understanding compilation mode for libraries : r/Angular2
I have an angular library that I recently upgraded to ng13 for ng12. After the upgrade I ran into a cyclical dependency error...
Read more >Newest 'angular-ivy+angular-library' Questions - Stack Overflow
in a project I wanted to switch my libs to the ivy partial compilation mode (angular 12). But got now some nasty circular...
Read more >Building an Angular Library with multiple entry points | Articles
We'll build a new Angular library from scratch, add multiple subentry ... ng-packagr will detect circular dependencies and throw an error.
Read more >Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start FreeTop Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
Top GitHub Comments
Ivy’s design is by its nature more sensitive to dependency cycles between components. A lot of Ivy’s benefits are realized by the “direct” references that it generates between components (instead of indirect references via
.ngfactory
files), but these direct references can also generate real cyclic references in ES module imports.Ivy applications currently deal with this problem through a workaround - we use a different mechanism to set component dependencies, which avoids cycles but breaks tree-shaking in the process. For Ivy libraries, we made a conscious decision not to silently work around the problem and compromise on code size and efficiency, but to generate real errors in the uncommon case of cyclic components.
Fortunately, working around this error should always be possible, if a little annoying. Usually, the cycle can be broken by breaking the “reverse dependency” - if component A depends on component B, ensure that component B’s file doesn’t have any other runtime dependencies on component A’s file. Since a common pattern for such dependencies is to import interfaces or other types,
import type
can be very useful here to tell the compiler that these imports aren’t important at runtime.If that’s not possible, components that crate cyclic references can always be moved into the same file, which completely eliminates the issue. Note that the Ivy compiler is fine if the project contains its own cycles, it’s just unwilling to introduce them on its own.
This issue has been automatically locked due to inactivity. Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.