Skip to content
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鈥檒l occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Ivy - 9.0.0-rc.1] Running `ngc` on a custom library throws error "Appears in the NgModule.imports of ..., but could not be resolved to an NgModule class" #33690

Closed
VladimirAmiorkov opened this issue Nov 8, 2019 · 4 comments

Comments

@VladimirAmiorkov
Copy link

@VladimirAmiorkov VladimirAmiorkov commented Nov 8, 2019

馃悶 bug report

Affected Package

@angular/common but I expect that others can also have this issue.

Is this a regression?

Yes, running ngc on a code of a library that uses Angular's packages has always works and the correct .metadata.json files have been created.

Description

Running ngc to generate the metadata.json of my custom library's source code fails when using the latest 9.0.0.x release, currently available in the @next tag at npm.

I am testing how to building my package will work when 9.0.0 comes out.

馃敩 Minimal Reproduction

As this requires compiling with ngc I have prepared a very simply package and you can download it here ngc issue.zip

Simply do the following:

  • Extract the archive and open it in a terminal
  • Install the npm packages with npm install
  • Trigger ngc by executing ./node_modules/.bin/ngc

The following error is thrown:

馃敟 Exception or Error



node_modules/@angular/common/common.d.ts:115:22 - error NG6002: Appears in the NgModule.imports of MyCommonModule, but could not be resolved to an NgModule class

115 export declare class CommonModule {
                         ~~~~~~~~~~~~
node_modules/@angular/common/common.d.ts:115:22 - error NG6003: Appears in the NgModule.exports of MyCommonModule, but could not be resolved to an NgModule, Component, Directive, or Pipe class

115 export declare class CommonModule {
                         ~~~~~~~~~~~~

馃實 Your Environment

Angular Version:



Angular CLI: 9.0.0-rc.1
Node: 10.15.2
OS: darwin x64
Angular: 9.0.0-rc.1
... common, compiler, compiler-cli, core

Package                      Version
------------------------------------------------------
@angular-devkit/architect    0.900.0-rc.1 (cli-only)
@angular-devkit/core         9.0.0-rc.1 (cli-only)
@angular-devkit/schematics   9.0.0-rc.1 (cli-only)
@schematics/angular          9.0.0-rc.1 (cli-only)
@schematics/update           0.900.0-rc.1 (cli-only)
rxjs                         6.5.3
typescript                   3.6.4

Anything else relevant?
I am hitting this error in preparation for Ivy and 9.0.0 of my custom Angular library. I would love some assistance before 9.0.0 is live because at the moment I cannot build my custom library when using Angular packages 9.0.0

@VladimirAmiorkov VladimirAmiorkov changed the title [Ivy - 9.0.0-rc.1] Running `ngc` on a custom library throws "Appears in the NgModule.imports of ..., but could not be resolved to an NgModule class" [Ivy - 9.0.0-rc.1] Running `ngc` on a custom library throws error "Appears in the NgModule.imports of ..., but could not be resolved to an NgModule class" Nov 8, 2019
@alexzuza

This comment has been minimized.

Copy link
Contributor

@alexzuza alexzuza commented Nov 8, 2019

Hey, it looks like you forgot to run Angular compatibility compiler(ngcc) first. This compiler prepares Angular code to work with new Ivy compiler(ngtsc).

So your actions are:

./node_modules/.bin/ngcc -p es2015

You can also compile other formats like fesm2015, fesm5, esm2015, esm5, main, module (See also https://aio-staging.firebaseapp.com/guide/migration-ngcc#can-i-customize-the-ngcc-options-in-the-postinstall-script)

then

./node_modules/.bin/ngc
@VladimirAmiorkov

This comment has been minimized.

Copy link
Author

@VladimirAmiorkov VladimirAmiorkov commented Nov 8, 2019

Thanks for replying. I did find out that but was wondering if that is correct. I was not sure if ngcc should be ran before ngc, because if I do this then there are no metadata json files created

@alexzuza

This comment has been minimized.

Copy link
Contributor

@alexzuza alexzuza commented Nov 8, 2019

@VladimirAmiorkov Ivy compiler is default compiler since 9.0.0-next.3(https://github.com/angular/angular/blob/master/CHANGELOG.md#breaking-changes-8). If you want to compile your library in ViewEngine mode then I would suggest you using enableIvy option in your tsconfig.json

"angularCompilerOptions": {
      "genDir": ".",
      "skipMetadataEmit": false,
      "skipTemplateCodegen": true,
      "strictMetadataEmit": true,
      "enableIvy": false   <------------------ try this
    },
@VladimirAmiorkov

This comment has been minimized.

Copy link
Author

@VladimirAmiorkov VladimirAmiorkov commented Nov 8, 2019

@alexzuza Awesome, thank you. My issue is resolved so I will close this issue.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can鈥檛 perform that action at this time.