2

I understand this error but i need help finding a solution.

Im making a CMS ui. It has a form.component.html which uses fields.component.html one of the fields is a field-set.component.html which re-imports fields.component.html

I want this recursive use of template to work some how.

note => this set up works in dev. It just cant compile. Also im pretty sure this used to compile before Ivy

Markup structure (base)

<form>
  <fields></fields>
</form>

Markup structure (fields)

<div class="fields">
<field-text></field-text>
<field-textarea></field-textarea>
<field-set></field-set> <!-- this has fields again -->
<field-select></field-select>
<field-date></field-date>
</div>

Markup structure (field-set)

<div class="field-set">
<fields [fieldSet]="true"></fields>
</div>

enter image description here

Angular CLI: 13.1.3
Node: 14.16.0
Package Manager: npm 6.14.11
OS: darwin x64

Angular: 13.1.2
... animations, common, compiler, compiler-cli, core, forms
... language-service, material, platform-browser
... platform-browser-dynamic, router

Package                         Version
---------------------------------------------------------
@angular-devkit/architect       0.1301.3
@angular-devkit/build-angular   13.1.3
@angular-devkit/core            13.1.3
@angular-devkit/schematics      13.1.3
@angular/cli                    13.1.3
@angular/fire                   7.2.0
@schematics/angular             13.1.3
ng-packagr                      13.1.3
rxjs                            6.6.7
typescript                      4.5.4
Omar
  • 2,726
  • 2
  • 32
  • 65
  • Can you show me how you structured your project? Having separate modules on each component? – smithnblack Feb 02 '22 at 08:36
  • Seems like your problem can be seen [here](https://angular.io/errors/NG3003). I'm searching for a solution, didn't find it yet but this may help you – Raphaël Balet Feb 18 '22 at 15:05
  • thank you guys i will look into these things. See markup added above for better context – Omar Feb 21 '22 at 18:29

1 Answers1

1

For what I can understand, this is not possible anymore because of the Circular Dependency Issue

Unfortunately, "remote scoping" code is side-effectful, which prevents tree shaking, and cannot be used in libraries. So when building libraries using the "compilationMode": "partial" setting, any component that would require a cyclic import will cause this NG3003 compiler error to be raised.

Here Ideas given by angular to fix your problem.

  • Try to re-arrange your dependencies to avoid the cycle. For example using an intermediate interface that is stored in an independent file that can be imported to both dependent files without causing an import cycle.
  • Move the classes that reference each other into the same file, to avoid any imports between them.
  • Convert import statements to type-only imports (using import type syntax) if the imported declarations are only used as types, as type-only imports do not contribute to cycles.
Raphaël Balet
  • 6,334
  • 6
  • 41
  • 78
  • Thank you for this. I will dive in soon. I added markup incase it help understand the issue better – Omar Feb 21 '22 at 18:29