-
Notifications
You must be signed in to change notification settings - Fork 25.3k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
IVY Error NG6002: Appears in the NgModule.imports of AppModule, but could not be resolved to an NgModule class #35399
Comments
any idea on this error? |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
Thx for sharing your solution, @houdass. However, yours seems to be different issue that than the one reported here. |
This comment has been minimized.
This comment has been minimized.
Not sure this will provide anyone relief or assist with figuring out what the root cause is, but cleaning my cache seemed to help resolve the issue. The only other step that I did was I ran a --prod serve after the clean. I do not know if the clean or --prod thing had anything to do with fixing it for me, or if maybe the combination of them did anything, but I can no longer repro this bug in my project. Note, I can run without --prod and still have successful builds going forward. Other than that, I saw this first when adding HttpClientModule as I was going through the tour of heroes tutorial. |
Hi @stevethemacguy , I just encountered the same issue and was able to track it down to one property in the tsconfig.json: What I tried with importHelper in their corresponding tsconfig.json:
Cheers |
When get NG6002 with a module issue as above, delete the top node_modules in the workspace (where you should have installed it), and rebuild libraries/apps. Seems like on first build, output is added to node_modules that gets occasionally confused. This 'trick" works for me with problems incrementally added angular material modules to a library and app. |
Ok, more details on this!
I thought setting importHelpers to false would cause the typescript compiler to include the helper methods into the bundle. And indeed this is happing. But not only once!! A quick look into the created bundles reveals following with importHelpers set to false: UMD BundleFESM2015 BundleMaybe this is also the reason why the bundle sizes grew? Cheers |
Hello,
Any suggestions please ^^ |
@paksouse, see my comment above in the thread. It has helped me and
others. Unfortunately it looks like a couple of conditions can drive
NG6002...if you have an issue when adding modules over time with Angular 9
then my workaround should do it.
…On Mon, Feb 17, 2020 at 8:28 AM paksouse ***@***.***> wrote:
Hello,
I have the same problem in my poject "NX monorepo project",
-
"importHelpers": true didnot help
-
"enableIvy": false for the libs and "enableIvy": true for the demo
project that inject the libs dinot work either.
Any suggestions please ^^
regards.
—
You are receiving this because you commented.
Reply to this email directly, view it on GitHub
<#35399?email_source=notifications&email_token=ABO2BYU74SUJI7MGBCUI6CDRDKGH7A5CNFSM4KUIUUC2YY3PNVWWK3TUL52HS4DFVREXG43VMVBW63LNMVXHJKTDN5WW2ZLOORPWSZGOEL6M76A#issuecomment-586993656>,
or unsubscribe
<https://github.com/notifications/unsubscribe-auth/ABO2BYTMKL6IFAG73LE57H3RDKGH7ANCNFSM4KUIUUCQ>
.
|
Hello, Same problem here. I tried to delete node_modules and reinstall packages again but didn't work. The "importHelpers" for me was true already. I need start a new angular project and I am thinking if I should start with Angular 9 |
@FranzZemen thanks for your suggestion but didnot works. |
For me, disable Ivy works! (To disable Ivy, you need add a flag "enableIvy" false in the file tsconfig.app.json. More information here: https://angular.io/guide/ivy) But, I dont know the consequences of doing this, and when I would can enable again. |
@paksouse and you are sure that you enabled importHelpers for your library? That's strange because at work I tried even more library repositories and this definitely solved the issues.. Hm. and as @rafastellato mentioned, for libraries ivy must be disabled, which is already told in the docs, though. Another point: For libraries installed by npm, you can't really set importHelpers to true, so you must struggle around with deleting node_modules, if it helps. |
For those who You need to specify the node_module folder in the Ex: If you have a workspace with the angular project in For more options you can go [here].(https://github.com/angular/angular/blob/master/packages/compiler-cli/ngcc/main-ngcc.ts#L20) |
Thank you for the responses. Adding "importHelpers" and deleting node modules has no effect. My (real) application does not use Angular CLI, so CLI solutions won't necessarily work. It's more likely an issue with how the angular2-highcharts library is exporting modules/classes, which is something I can't control. |
thank you for your answers @Embraser01 @flash-me |
In ES2015 and ES5, class identifiers may have aliases. Previously, the `NgccReflectionHost`s recognized the following formats: - ES2015: `const MyClass = MyClass_1 = class ...` - ES5: ```js var MyClass = (function () { function InnerClass() {} InnerClass_1 = InnerClass; ... }()); ``` In addition to the above, this commit adds support for recognizing an alias outside the IIFE in ES5 (which was previously not supported): `var MyClass = MyClass_1 = (function () { ... }());` Fixes angular#35399
In ES5 and ES2015, class identifiers may have aliases. Previously, the `NgccReflectionHost`s recognized the following formats: - ES5: ```js var MyClass = (function () { function InnerClass() {} InnerClass_1 = InnerClass; ... }()); ``` - ES2015: ```js let MyClass = MyClass_1 = class MyClass { ... }; ``` In addition to the above, this commit adds support for recognizing an alias outside the IIFE in ES5 classes (which was previously not supported): ```js var MyClass = MyClass_1 = (function () { ... }()); ``` Fixes angular#35399
In ES5 and ES2015, class identifiers may have aliases. Previously, the `NgccReflectionHost`s recognized the following formats: - ES5: ```js var MyClass = (function () { function InnerClass() {} InnerClass_1 = InnerClass; ... }()); ``` - ES2015: ```js let MyClass = MyClass_1 = class MyClass { ... }; ``` In addition to the above, this commit adds support for recognizing an alias outside the IIFE in ES5 classes (which was previously not supported): ```js var MyClass = MyClass_1 = (function () { ... }()); ``` Jira issue: [FW-1869](https://angular-team.atlassian.net/browse/FW-1869) Fixes angular#35399
@CandyMan00 Even if this works, it's just a dirty hack while developing. For every new line of code I would have to copy the dist folder manually and run ngcc. I mean ngcc does something when I use |
@dhubens - just to clarify... I am not proposing to publish the library. Just package it into a
The main downside of this is that you need to rebuild and re-pack your library, and then re-install it into your test library each time you want to test a change. But generally, in my experience, you will work mostly with unit tests locally to the library for the most part, and then treat tests in your test project as an e2e test. If you want to use the test project as more of a unit test environment, then the approach is to include the actual source of the library (TS files) directly via pathMappings in your test project. This avoids ngcc altogether as ngtsc will build the library as part of your application, allowing fast turnaround. The downside of this is that you are testing a direct ivy build of you library and not the ViewEngine build that will actually be deployed. |
This worked for me |
Deleting |
Try disabling ivy. |
Disabling Ivy does work but then what's the point of upgrading to angular 9? |
cheers |
As it turns out, for us the issue was caused by the presence of |
Don't struggle around with packaging for developing locally. .. https://docs.npmjs.com/cli/link.html cheers |
@petebacondarwin We are trying to upgrade monorepo to Angular V9 and are maintaining it by rush.js (https://rushjs.io/pages/intro/welcome/) and we are using pnpm as a package manager. I am facing the above mentioned IVY Error NG6002 error while running tests of libraries. ("enableIvy" flag is set to false for all the libraries and application too. Have considered all the above suggestions but nothing helped) . From the documentation and the error that is shown during rush test, it is clear that the corresponding module(here in our case @angular/flex-layout) has not been processed correctly by the ngcc compiler. Documentation says we need to run "ngcc" command for the modules to be IVY compliant. But somehow pnpm is not picking up postinstall script(which includes ngcc command) present in package.json of each library and is not executed. Even though we are able to install and build(done by ng-packagr) the entire project which includes both libraries and demo app, we are blocked because of tests throwing this issue. Any suggestions or help around this would be greatly appreciated. Note: Everything works fine individually meaning running install, build and test using yarn in each library and application works but collectively when we run rush test, we are facing this issue. (Reason : because we don't face symlinks issue when we run projects individually) |
|
@yamaha252 - is this when ngcc processes the libraries? Do you use pathMappings to relate library2 to library1? If so, then may be this PR that just landed will help: #36180. But without more information about your specific scenario it is difficult to know. |
@petebacondarwin nope, I just use All the libraries are built with disabled Ivy and Errors are on compilation
|
I'm afraid that ngcc is not able to follow symlinks, so this is probably the root of your problem: ngcc is not able to compile |
@petebacondarwin thank you! I understood, you're right. If I use installed |
Finally, I solve my problem. I have to have Ivy enabled for development to use |
This was my problem when trying to work locally. When I |
@clement911 Please can you explain which folder exactly you removed? |
@yazan-mehrez |
@clement911 I don't have this folder, I did all the solutions here but I'm still stuck. flex layout is not working with ivy properly. |
I'm using npm link as described here which creates a link within node_modules and ngcc is able to handle it. So it works cheers |
@flash-me - I am glad that it is working for you. But just to be clear, when ngcc finds a symlink it does not follow it. Now it may be that the CLI is following symlinks and then passing the source of the symlink to ngcc, which may well work. |
@petebacondarwin Good to know that the symlink support is related to cli and not ngcc. I just wanted to mention it. sorry if my formulation sound kinda offensive cheers |
No worries @flash-me ! |
This worked for me also |
This issue has been automatically locked due to inactivity. Read more about our automatic conversation locking policy. This action has been performed automatically by a bot. |
🐞 bug report
Affected Package
The issue might be related to packageng-packagr
Is this a regression?
Yes, the previous version in which this bug was not present was: 8.2.14Description
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)
Our real app, which uses a shared module, throws a slightly different 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:
But this produces the following 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
Expected behavior: IVY builds the app
Actual behavior: IVY displays an error.
🔥 Exception or Error
🌍 Your Environment
Angular Version:
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.
The text was updated successfully, but these errors were encountered: