Skip to content

AOT compiler doesn't generate *.ngfactory.ts files for 3rd party components in node_modules #11889

Closed

Description

@mattlewis92

I'm submitting a ... (check one with "x")

[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

Reproduction of the problem
Checkout this repo: https://github.com/mattlewis92/angular2-tv-tracker

npm install
npm run ngc

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.

screen shot 2016-09-24 at 15 35 24

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 ]

    N/A

  • Language: [all | TypeScript X.X | ES6/7 | ES5]
    Typescript

  • Node (for AoT issues): node --version =
    v5.11.0

Activity

  1. kylecordes commented on Sep 24, 2016

    @kylecordes

    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.

  2. mattlewis92 commented on Sep 24, 2016

    @mattlewis92
    ContributorAuthor

    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.

    On 24 Sep 2016, at 15:50, Kyle Cordes notifications@github.com wrote:

    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.

  3. vicb commented on Sep 24, 2016

    @vicb
    Contributor

    @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.

  4. mattlewis92 commented on Sep 24, 2016

    @mattlewis92
    ContributorAuthor

    @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 😀

  5. reopened this on Sep 24, 2016
  6. mattlewis92 commented on Sep 24, 2016

    @mattlewis92
    ContributorAuthor

    @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?
  7. vicb commented on Sep 24, 2016

    @vicb
    Contributor

    Thanks for reporting.

    Yep, they should be exported.

    Could you please attach a minimal repro. We'll work on a better error message. Thanks.

  8. added
    area: core
    on Sep 24, 2016
  9. mattlewis92 commented on Sep 24, 2016

    @mattlewis92
    ContributorAuthor

    Will get that done tomorrow, thanks!

  10. self-assigned this
    on Sep 24, 2016
  11. mattlewis92 commented on Sep 25, 2016

    @mattlewis92
    ContributorAuthor

    @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 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)

  12. assigned and unassigned on Sep 27, 2016
  13. 17 remaining items

  14. added a commit that references this issue on Oct 24, 2016
    a838aba
  15. mattlewis92 commented on Oct 24, 2016

    @mattlewis92
    ContributorAuthor

    Awesome, thanks a bunch @vicb for fixing this! 😀

  16. vicb commented on Oct 24, 2016

    @vicb
    Contributor

    That was actually a team work together with @tbosch and @chuckjaz

    Have you tested the fix on your app ?

  17. mattlewis92 commented on Oct 24, 2016

    @mattlewis92
    ContributorAuthor

    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:

    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
    

    Minimal repro here: https://github.com/mattlewis92/angular2-compiler-bug

  18. vicb commented on Oct 24, 2016

    @vicb
    Contributor

    @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

      "peerDependencies": {
        "@angular/core": "angular/core-builds",
        "rxjs": "^5.0.0-beta.12",
        "zone.js": "^0.6.25"
      },
    

    while it was

      "dependencies": {
        "@angular/core": "^2.0.1",
        "rxjs": "^5.0.0-beta.12",
        "zone.js": "^0.6.25"
      },
    

    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.

  19. mattlewis92 commented on Oct 24, 2016

    @mattlewis92
    ContributorAuthor

    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 👍

  20. added a commit that references this issue on Oct 27, 2016
    0fd859c
  21. angular-automatic-lock-bot commented on Sep 10, 2019

    @angular-automatic-lock-bot

    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.

  22. locked and limited conversation to collaborators on Sep 10, 2019
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: corefreq2: mediumhotlist: components teamhotlist: error messagestype: bug/fix

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions