Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Angular 10 Libraries and IVY/ngcc Compatibility

I have a library that needs to be distributed via npm. The recommendation for Angular 10 still seems to be that such libraries should be compiled with IVY disabled but that the Angular CLI will ensure that the library is still compatible with an app that has IVY enabled.

With my library, if I build it with IVY it works as expected. Yet if I disable IVY when building, when I come to import the library I get the following error:

ERROR in node_modules/@me/my-module/lib/my-module.module.d.ts:1:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class.

This likely means that the library (@me/my-module) which declares MeMYModule has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so. Also consider checking with the library's authors to see if the library is expected to be compatible with Ivy.

Am I missing something? I have found lots of similar problems, but none of the solutions seem to work.

like image 828
Matthew Dolman Avatar asked Aug 28 '20 05:08

Matthew Dolman


People also ask

What is not compatible with Angular ivy?

Angular Error - ...not compatible with Angular Ivy The typical full message looks like this: This likely means that the library (@***) which declares *** has not been processed correctly by ngcc, or is not compatible with Angular Ivy. Check if a newer version of the library is available, and update if so.

Does Angular 10 enable Ivy by default?

Ivy enabled by default This is possible in both angular versions 9 and 10 to ensure a smoother transition from View Engine to Ivy. Libraries can be AOT-compiled directly to Ivy instructions and metadata, but this is not recommended.

How do I make Angular library work with Ivy?

If you maintain or want to help maintain an Angular library, you now know how to respond to Angular Ivy: Keep publishing a View Engine AOT-compiled bundle for Angular version 9. Publish an Ivy AOT-compiled bundle for Angular version 10. Add your library to the Angular Ivy library compatibility validation project.

What is Ivy Ngcc?

Ivy and librarieslink Ivy applications can be built with libraries that were created with the View Engine compiler. This compatibility is provided by a tool known as the Angular compatibility compiler ( ngcc ). CLI commands run ngcc as needed when performing an Angular build.


1 Answers

I'd faced similar problem few days ago. I solved it by adding the following script inside my package.json file.

"scripts": {
    "postinstall": "ngcc"
  }
like image 193
snsakib Avatar answered Oct 01 '22 13:10

snsakib