18

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.

Matthew Dolman
  • 1,732
  • 7
  • 25
  • 49

2 Answers2

21

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

"scripts": {
    "postinstall": "ngcc"
  }
snsakib
  • 1,062
  • 9
  • 14
  • 1
    you can even `npm run postinstall` to try to figure if it will work. – JoeCool Nov 21 '20 at 14:23
  • 2
    Facing the same problem I tried enabling Ivy without success of building my library. De we add `postinstall` to library's package or to app's ? I tried both and still have the same error :/ – Thibaud Renaux Nov 23 '20 at 15:54
  • 3
    This does not work with Angular 16 I get: ALERT: As of Angular 16, "ngcc" is no longer required and not invoked during CLI builds. You are seeing this message because the current operation invoked the "ngcc" command directly. This "ngcc" invocation can be safely removed. A common reason for this is invoking "ngcc" from a "postinstall" hook in package.json. In Angular 17, this command will be removed. Remove this and any other invocations to prevent errors in later versions. – MadMac Jun 13 '23 at 00:39
4

I'd faced similar problem few days ago, integrating fluuterwave into an Angular 16 project, this error was shown

flutterwave.module.d.ts(1, 22): This likely means that the library (flutterwave-angular-v3) which declares FlutterwaveModule 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.

I solved it by adding the following script inside my package.json file.

    {
      ...
      "scripts": {
        ...
        "postinstall": "npx --package @angular/compiler-cli@15.2.9 --yes ngcc",
        ...
       },
       ...
    }
Sunday Etom
  • 171
  • 1
  • 5
  • This solution worked for me as I had the exact case of flutterwave-v3 in Angular 16. Don't forget to re-run "npm install" after adding the postinstall script. – xodeeq Aug 01 '23 at 19:14
  • Were you able to get over the null injection error at the point when the Flutterwave service actually gets called in your Angular 16 application. Your fix ensures that my app doesn't break at build time but it still does because the Flutterwave service is not "Ivy compatible". ERROR NullInjectorError: R3InjectorError(AppModule)[Flutterwave -> Flutterwave]: NullInjectorError: No provider for Flutterwave! – xodeeq Aug 03 '23 at 12:31