Skip to content

platformBrowser().bootstrapModule does not work under Closure Compiler ADVANCED_OPTIMIZATIONS #36618

Closed

Description

@DavidANeil

🐞 bug report

Affected Package

@angular/platform-browser, @angular/compiler-cli, @angular/core

Is this a regression?

Lack of parity between Ivy and ViewEngine.

Description

  • When compiling an application with Ivy (aot: true) with an entry point that contains platformBrowser().bootstrapModule(AppModule) and then running it through the Closure Compiler's advanced optimizations:

    • BrowserModule's providers are removed as dead code which causes the application to fail to bootstrap with the error "No ErrorHandler. Is platform module (BrowserModule) included?"
  • Compiling the same application with Closure's simple optimizations:

    • Application renders as expected.
  • Changing the entry point to use ɵrenderComponent(AppComponent) and using advanced optimizations:

    • Simple application renders as expected.
    • Complex app fails with '${type.name}' is neither 'ComponentType' or 'DirectiveType'. for just about every Angular-owned dependency (e.g. RouterModule)

🌍 Environment

Angular Version:

"@angular/animations": "9.1.1",
"@angular/bazel": "9.1.1",
"@angular/common": "9.1.1",
"@angular/compiler": "9.1.1",
"@angular/compiler-cli": "9.1.1",
"@angular/core": "9.1.1",
"@angular/forms": "9.1.1",
"@angular/platform-browser": "9.1.1",
"@angular/platform-browser-dynamic": "9.1.1",
"@angular/router": "9.1.1",

Activity

  1. added
    area: compiler
    on Apr 14, 2020
  2. added this to the needsTriage milestone on Apr 14, 2020
  3. DavidANeil commented on Apr 15, 2020

    @DavidANeil
    Author

    It turns out ɵrenderComponent worked for the simple example I built, but doesn't work for an application that has deps on anything published by Angular (e.g. RouterModule). I've edited the original post to reflect this.

  4. DavidANeil commented on Apr 15, 2020

    @DavidANeil
    Author

    Closure is changing something like

    function CommonModule() {
    }
    CommonModule.ɵmod = ɵngcc0.ɵɵdefineNgModule({ type: CommonModule });

    To

    function CommonModule() {
    }
    ɵngcc0.ɵɵdefineNgModule({ type: CommonModule });
  5. DavidANeil commented on Apr 15, 2020

    @DavidANeil
    Author

    I'm 90% certain that having ngcc emit /** @nocollapse */ comments would fix this.

  6. DavidANeil commented on Apr 16, 2020

    @DavidANeil
    Author

    I've confirmed that #36652 does actually fix this, and I was able to successfully bootstrap our application using Ivy and advanced optimizations with that patch applied.

  7. added a commit that references this issue on Jun 10, 2020
    fe84683
  8. added a commit that references this issue on Jun 11, 2020
    eca8d11
  9. added a commit that references this issue on Jun 25, 2020
    736afef
  10. angular-automatic-lock-bot commented on Jul 12, 2020

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

  11. locked and limited conversation to collaborators on Jul 12, 2020
  12. added a commit that references this issue on Sep 5, 2020
    d189cfa
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

area: compilerstate: confirmedstate: has PRtype: bug/fix

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions