0

I have a requirement to upgrade a library to angular 12...I have done this. Compiling this library with ivy full compilation mode succeeds but it turns out you can't publish a library compiled this way to npm???

Setting "enableIvy":false and "compilationMode": "partial" as suggested in many posts throws the error

Compiling with Angular in legacy View Engine compilation mode. Angular structure loaded both synchronously and asynchronously

This error does not seem to have a definite solution??

How is someone supposed to keep current with their Angular version and publish their library to npm in this kind of environment?

Mahdi Zarei
  • 5,644
  • 7
  • 24
  • 54
Funn_Bobby
  • 647
  • 1
  • 20
  • 57
  • Does this answer your question? [angular 9 library publish error "Trying to publish a package that has been compiled by Ivy"](https://stackoverflow.com/questions/60234048/angular-9-library-publish-error-trying-to-publish-a-package-that-has-been-compi), [How to compile a library without Ivy?](https://stackoverflow.com/questions/59113052/how-to-compile-a-library-without-ivy) – D M Jan 07 '22 at 21:36
  • 1
    There's more information about *why* `ViewEngine`-compiled libraries are required in [this GitHub issue comment](https://github.com/angular/angular/issues/37973#issuecomment-656024069). Tl;dr forward compatibility. – D M Jan 07 '22 at 21:40
  • Everything that I can find or read is that Angular 12 deprecates ViewEngine compilation...so which is it? this methodology seems half baked and thrown on developers that depend on a stable system to be able to do their jobs. I NEED to be able to build this code to NPM after upgrading. I'm sure there are others out there creating libraries in the same boat, I don't understand why they would do this without a definite way to achieve building a library to NPM – Funn_Bobby Jan 10 '22 at 15:37
  • [Based on this blog post](https://blog.lacolaco.net/2021/02/angular-ivy-library-compilation-design-in-depth-en/), it looks like your configuration is incorrect. `"compilationMode": "partial"` is only valid when `"enableIvy": "true"`. The Angular docs confirm that, ["for publishing to npm use the partial-Ivy format"](https://angular.io/guide/creating-libraries#publishing-libraries), so `"enableIvy": "true"` and `"compilationMode": "partial"` seems to be the way to go after Angular 12. – D M Jan 10 '22 at 15:54
  • ...at least if you don't have any `ViewEngine` dependencies and you aren't required to support Angular 11. Note that `ViewEngine` was deprecated in Angular 12 but wasn't removed until Angular 13. – D M Jan 10 '22 at 16:01
  • [This answer](https://stackoverflow.com/a/70003911/14956277) talks about using `ng-packagr` to build an Angular 12 library for npm. – D M Jan 10 '22 at 16:04
  • Right...and "enableIvy": "true" with "compilationMode" : 'partial" throws hundreds of circular dependency errors but not for applications...just for libraries, it makes no sense! Here is stackOverflow explaining it without an accepted answer https://stackoverflow.com/questions/69268944/circular-dependency-with-ivy-partial – Funn_Bobby Jan 10 '22 at 16:07

1 Answers1

0

For me Setting "enableIvy":false and "compilationMode": "partial" as suggested in many posts throws many recursive errors...I'm not sure why "compilationMode": "partial" works differently than "compilationMode": "full".

What I found was that I had inappropriately imported a component inside my library using public.api
public/api should only be used outside the library for importing...inside the librarary I made sure that I was doing direct imports of components and everything started compiling properly under "compilationMode": "partial"

Funn_Bobby
  • 647
  • 1
  • 20
  • 57