Useful or not, from you.
angular IVY Error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class

🐞 bug report

Affected Package

<!-- Can you pin-point one or more @angular/* packages as the source of the bug? --> <!-- ✍️edit: --> The issue might be related to package ng-packagr

Is this a regression?

<!-- Did this behavior use to work in the previous version? --> <!-- ✍️--> Yes, the previous version in which this bug was not present was: 8.2.14

Description

Possible duplicate of #35331, #34983, #35255, and #30972, but I'm including a minimal reproduction repo. Building with IVY throws the following error (see the Exception or Error section)

StackBlitz Error

Our real app, which uses a shared module, throws a slightly different error:

Concise Error

Running the ng-packagr postinstall script adds "ivy_ngcc" folders to some of our other dependencies, but does not touch the angular2-highcharts library. The library does not use the Angular Package Format, which might be part of the problem, but I'm not the library's author and have never built an ES6/angular library myself, so I'm just guessing at a potential fix.

Unfortunately, the library is no longer maintained, but it is one of our app's core/major dependencies. I also attempted to rebuild the library from the source files after adding the following to the library's package.json file:

<pre><code> "postinstall": "ngcc --properties es2015 browser module main --first-only --create-ivy-entry-points", "ngPackage": { "lib": { "entryFile": "index.d.ts" } }, </pre></code>

But this produces the following error:

Error

There is no "files" array provided in the library's package.json file, so I'm not sure what the error is referring to. I fixed all Angular 9-related issues prior to re-building the library, so I assume it has to do with the way it's packaged or how it exports the modules/components.

🔬 Minimal Reproduction

StackBlitz https://angular-ivy-cant-be-resolved.stackblitz.io

GitHub repo in case StackBlitz isn't working: https://github.com/stevethemacguy/angular-ivy-cant-be-resolved-bug

Steps to Reproduce

  1. Download or clone the repo
  2. npm install
  3. ng build (or ng serve)

Expected behavior: IVY builds the app Actual behavior: IVY displays an error.

🔥 Exception or Error

<pre><code>ERROR in node_modules/angular2-highcharts/dist/index.d.ts:8:22 - error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class

8 export declare class ChartModule { </code></pre>

🌍 Your Environment

Angular Version: <pre><code>Angular CLI: 9.0.2 Node: 10.15.3 OS: darwin x64

Angular: 9.0.1 ... animations, common, compiler, compiler-cli, core, forms ... language-service, platform-browser, platform-browser-dynamic ... router Ivy Workspace: Yes

Package Version

@angular-devkit/architect 0.900.2 @angular-devkit/build-angular 0.900.2 @angular-devkit/build-optimizer 0.900.2 @angular-devkit/build-webpack 0.900.2 @angular-devkit/core 9.0.2 @angular-devkit/schematics 9.0.2 @angular/cli 9.0.2 @ngtools/webpack 9.0.2 @schematics/angular 9.0.2 @schematics/update 0.900.2 rxjs 6.5.4 typescript 3.7.5 webpack 4.41.2

</code></pre>

Anything else relevant? After disabling IVY, our real app successfully builds in AOT (prod mode) using Angular 9.0.1, so the issue seems to be an Angular regression that is un-related to our app (except for the angular2-highcharts dependency). Our app uses a custom angular/webpack build. It does not use Angular CLI.

That's a useful answer
Without any help

Hey, Finally i decided to disable Ivy to build in '--prod'. I have my last question : Is it advisable to enable Ivy for ng build --prod or not ? regards.

  • For angular libraries the recommendation is to disable Ivy when publishing in order To stay compatible as long as possible.
  • For angular apps you may enable Ivy, so you can benefit from the advantages of the Ivy Compiler. Every library used in the app will also be compiled, if not already.