You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
AOT compiler doesn't generate *.ngfactory.ts files for 3rd party components in node_modules #11889
[x] bug report => search github for a similar issue or PR before submitting
[ ] feature request
[ ] support request => Please do not submit support request here, instead see https://github.com/angular/angular/blob/master/CONTRIBUTING.md#question
Current behavior
When running ngc the compiler doesn't codegen components inside node_modules when the component isn't exported (export * from './my.component';) from the module. There are no errors emitted and all the *.metadata.json files for the libraries exist.
Expected behavior
For ngc to successfully codegen all 3rd party components without having to export the components publicly
You will then see that only one ngfactory.ts module file is emitted for each 3rd party module inside of the aot/module_modules folder, but none of the other components are codegen'd. As you can see from the screenshot, the reference to the './directives/calendarTooltip.directive.ngfactory' file is created but the file itself doesn't exist.
If you need any more info let me know!
Please tell us about your environment:
OSX
Angular version: 2.0.X
2.0.1
Browser: [all | Chrome XX | Firefox XX | IE XX | Safari XX | Mobile Chrome XX | Android X.X Web Browser | iOS XX Safari | iOS XX UIWebView | iOS XX WKWebView ]
I'm not deep enough to comment on whether this is a bug per se, but my impression from various words it is slowed by from the Angular team is that "For ngc to successfully codegen all 3rd party components" is not necessarily the actual expected behavior. Rather, once all the various bits are lined up correctly (possibly the case already?) it would be more expected that third-party components would ship with their ngc output already in place, and that ngc in a particular project would only do the work for that project, not for third-party stuff. Of course, disregard this once someone in the know answers for real.
That was my first thought as well, but looking at the way that ng-bootstrap and angular material do it, shipping the *.metadata.json files with the module is sufficient.
I'm not deep enough to comment on whether this is a bug per se, but my impression from various words it is slowed by from the Angular team is that "For ngc to successfully codegen all 3rd party components" is not necessarily the actual expected behavior. Rather, once all the various bits are lined up correctly (possibly the case already?) it would be more expected that third-party components would ship with their ngc output already in place, and that ngc in a particular project would only do the work for that project, not for third-party stuff. Of course, disregard this once someone in the know answers for real.
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub, or mute the thread.
@mattlewis92 yep only the metadata files are required. All the factory are generated by ngc when building the app so that any improvement made to the angular compiler over time could benefit to the libs.
@vicb sorry I think you misunderstood me, I'm already shipping the metadata files with my libraries, but ngc isn't codegenning the 3rd party libraries properly. If you check out the repo I linked to you'll see what I mean 😀
@vicb I did some digging and it turns out the cause of the issue was that the component classes weren't exported (export * from './name.component';) from the dependency in node_modules, only the NgModule class was exported.
So my question now is:
If this isn't intentional can it be fixed (My use case is I have some components in my libraries that are only used internally and I don't want people using them until their API's are stable - I currently leverage NgModule to include them in declarations but not in exports. If I now have to export them then people will start using these private components and will moan when the API changes).
If this is intentional / can't be fixed, then there should at least be an error message from ngc when the compiler couldn't codegen the component as it wasn't exported. I guess it should be able to detect this from the NgModule?
There's an explanation in the readme, if you need more detail let me know 😄 (basically running npm run ngc from this repo should throw an error that node_modules/mwl-example-ng2-module/dist/src/demo.component.ts could not be codegen'd as it wasn't exported from the module - currently everything appears to compile with no errors)
I just tested it and it doesn't actually seem to be working, it's failing with the error:
Error: Unexpected value 'DemoModule' imported by the module 'AppModule'
at /Users/mattlewis/Code/open-source/angular2-compiler-bug/node_modules/@angular/compiler/bundles/compiler.umd.js:14065:37
at Array.forEach (native)
at CompileMetadataResolver.getNgModuleMetadata (/Users/mattlewis/Code/open-source/angular2-compiler-bug/node_modules/@angular/compiler/bundles/compiler.umd.js:14050:46)
at /Users/mattlewis/Code/open-source/angular2-compiler-bug/node_modules/@angular/compiler/bundles/compiler.umd.js:12819:42
at Array.forEach (native)
at analyzeNgModules (/Users/mattlewis/Code/open-source/angular2-compiler-bug/node_modules/@angular/compiler/bundles/compiler.umd.js:12818:17)
at OfflineCompiler.compileModules (/Users/mattlewis/Code/open-source/angular2-compiler-bug/node_modules/@angular/compiler/bundles/compiler.umd.js:12876:20)
at CodeGenerator.codegen (/Users/mattlewis/Code/open-source/angular2-compiler-bug/node_modules/@angular/compiler-cli/src/codegen.js:109:30)
at codegen (/Users/mattlewis/Code/open-source/angular2-compiler-bug/node_modules/@angular/compiler-cli/src/main.js:7:81)
at Object.main (/Users/mattlewis/Code/open-source/angular2-compiler-bug/node_modules/@angular/tsc-wrapped/src/main.js:30:16)
Compilation failed
What happens is that the module had its own version of angular/core and then annotations are not recognized.
This change would make the module use the annotations from the single angular install.
We'll improve UX by printing an error message in this case.
Ah, npm would have been deduping it before I was using the nightly builds from github. Thanks a bunch for looking into that and apologies for wasting your time. I've published a new version of the 3rd party lib and I can confirm everything is getting codegen'd properly now 👍
Activity
kylecordes commentedon Sep 24, 2016
I'm not deep enough to comment on whether this is a bug per se, but my impression from various words it is slowed by from the Angular team is that "For ngc to successfully codegen all 3rd party components" is not necessarily the actual expected behavior. Rather, once all the various bits are lined up correctly (possibly the case already?) it would be more expected that third-party components would ship with their ngc output already in place, and that ngc in a particular project would only do the work for that project, not for third-party stuff. Of course, disregard this once someone in the know answers for real.
mattlewis92 commentedon Sep 24, 2016
That was my first thought as well, but looking at the way that ng-bootstrap and angular material do it, shipping the *.metadata.json files with the module is sufficient.
vicb commentedon Sep 24, 2016
@mattlewis92 yep only the metadata files are required. All the factory are generated by ngc when building the app so that any improvement made to the angular compiler over time could benefit to the libs.
mattlewis92 commentedon Sep 24, 2016
@vicb sorry I think you misunderstood me, I'm already shipping the metadata files with my libraries, but ngc isn't codegenning the 3rd party libraries properly. If you check out the repo I linked to you'll see what I mean 😀
mattlewis92 commentedon Sep 24, 2016
@vicb I did some digging and it turns out the cause of the issue was that the component classes weren't exported (
export * from './name.component';) from the dependency innode_modules, only theNgModuleclass was exported.So my question now is:
declarationsbut not inexports. If I now have to export them then people will start using these private components and will moan when the API changes).NgModule?vicb commentedon Sep 24, 2016
Thanks for reporting.
Yep, they should be exported.
Could you please attach a minimal repro. We'll work on a better error message. Thanks.
mattlewis92 commentedon Sep 24, 2016
Will get that done tomorrow, thanks!
mattlewis92 commentedon Sep 25, 2016
@vicb I've put together a minimal repro here: https://github.com/mattlewis92/angular2-compiler-bug
There's an explanation in the readme, if you need more detail let me know 😄 (basically running
npm run ngcfrom this repo should throw an error thatnode_modules/mwl-example-ng2-module/dist/src/demo.component.tscould not be codegen'd as it wasn't exported from the module - currently everything appears to compile with no errors)17 remaining items
fix(compiler): walk third party modules (#12453)
mattlewis92 commentedon Oct 24, 2016
Awesome, thanks a bunch @vicb for fixing this! 😀
vicb commentedon Oct 24, 2016
That was actually a team work together with @tbosch and @chuckjaz
Have you tested the fix on your app ?
mattlewis92 commentedon Oct 24, 2016
Ah, my thanks to both of them as well! :)
I just tested it and it doesn't actually seem to be working, it's failing with the error:
Minimal repro here: https://github.com/mattlewis92/angular2-compiler-bug
vicb commentedon Oct 24, 2016
@mattlewis92 the issue is actually in your code !
We just went into a debug session with @tbosch, you problem is in your nested module,
its package.json should be
while it was
What happens is that the module had its own version of angular/core and then annotations are not recognized.
This change would make the module use the annotations from the single angular install.
We'll improve UX by printing an error message in this case.
Thanks for reporting this issue.
mattlewis92 commentedon Oct 24, 2016
Ah, npm would have been deduping it before I was using the nightly builds from github. Thanks a bunch for looking into that and apologies for wasting your time. I've published a new version of the 3rd party lib and I can confirm everything is getting codegen'd properly now 👍
fix(compiler): walk third party modules (#12453)
angular-automatic-lock-bot commentedon Sep 10, 2019
This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.
Read more about our automatic conversation locking policy.
This action has been performed automatically by a bot.