Skip to content

Production build using buildOptimizer is broke but works without buildOptimizer (Angular v6/v7) #17255

Closed

Description

@ClemensSchneider

🐞 bug report

Affected Package

The issue is caused by package @angular-devkit/build-angular (this is my assumption)

Is this a regression?

Hard to tell as build-dependencies changed from Angular v5 to Angular v6 / v7, right?
Building the original v5 application using ng build --prod --build-optimizer=true spit out a working application at least.

Description

Building itself works but when trying to launch the application in the browser, an error is logged to the console:

main.8cc841c62bc65dc4efeb.js:1 Uncaught TypeError: (intermediate value)(intermediate value) is not a function
    at main.8cc841c62bc65dc4efeb.js:1
    at Object.RCq4.e.exports.12.../apply (main.8cc841c62bc65dc4efeb.js:1)
    at i (main.8cc841c62bc65dc4efeb.js:1)
    at main.8cc841c62bc65dc4efeb.js:1
    at main.8cc841c62bc65dc4efeb.js:1
    at main.8cc841c62bc65dc4efeb.js:1
    at Object.RCq4.e.exports.32../lib/Promise (main.8cc841c62bc65dc4efeb.js:1)
    at i (main.8cc841c62bc65dc4efeb.js:1)
    at main.8cc841c62bc65dc4efeb.js:1
    at Object.RCq4.e.exports.1.../callbacks (main.8cc841c62bc65dc4efeb.js:1)

When setting buildOptimizer to false, everything works out as expected (no error is logged and application launches).

🔬 Minimal Reproduction

Check out https://github.com/ClemensSchneider/angular-buildoptimizer-bug/tree/angular7 (or https://github.com/ClemensSchneider/angular-buildoptimizer-bug/tree/angular6 for the Angular v6 version).

Run yarn to install dependencies, then run yarn build to build the production build with buildOptimizer enabled.
Serve the resulting artifacts in dist/build-optimizer-bug with a regular http-server and open the application in the browser. You can see, that it errors out without displaying anything.

Then, turn off buildOptimizer in angular.json and run yarn build again. Open the resulting artifacts in the browser again and see, that everything works as expected.

🔥 Exception or Error


main.8cc841c62bc65dc4efeb.js:1 Uncaught TypeError: (intermediate value)(intermediate value) is not a function
    at main.8cc841c62bc65dc4efeb.js:1
    at Object.RCq4.e.exports.12.../apply (main.8cc841c62bc65dc4efeb.js:1)
    at i (main.8cc841c62bc65dc4efeb.js:1)
    at main.8cc841c62bc65dc4efeb.js:1
    at main.8cc841c62bc65dc4efeb.js:1
    at main.8cc841c62bc65dc4efeb.js:1
    at Object.RCq4.e.exports.32../lib/Promise (main.8cc841c62bc65dc4efeb.js:1)
    at i (main.8cc841c62bc65dc4efeb.js:1)
    at main.8cc841c62bc65dc4efeb.js:1
    at Object.RCq4.e.exports.1.../callbacks (main.8cc841c62bc65dc4efeb.js:1)

🌍 Your Environment

Angular Version (v7):


Angular CLI: 7.2.1
Node: 8.11.1
OS: win32 x64
Angular: 7.2.0
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.12.1
@angular-devkit/build-angular     0.12.1
@angular-devkit/build-optimizer   0.12.1
@angular-devkit/build-webpack     0.12.1
@angular-devkit/core              7.2.1
@angular-devkit/schematics        7.2.1
@angular/cli                      7.2.1
@ngtools/webpack                  7.2.1
@schematics/angular               7.2.1
@schematics/update                0.12.1
rxjs                              6.3.3
typescript                        3.2.2
webpack                           4.23.1

Angular Version (v6):


Angular CLI: 6.2.9
Node: 8.11.1
OS: win32 x64
Angular: 6.1.10
... animations, common, compiler, compiler-cli, core, forms
... http, language-service, platform-browser
... platform-browser-dynamic, router

Package                           Version
-----------------------------------------------------------
@angular-devkit/architect         0.8.9
@angular-devkit/build-angular     0.8.9
@angular-devkit/build-optimizer   0.8.9
@angular-devkit/build-webpack     0.8.9
@angular-devkit/core              0.8.9
@angular-devkit/schematics        0.8.9
@angular/cli                      6.2.9
@ngtools/webpack                  6.2.9
@schematics/angular               0.8.9
@schematics/update                0.8.9
rxjs                              6.2.2
typescript                        2.9.2
webpack                           4.16.4

Anything else relevant?

The module on which the build optimization chokes is https://www.npmjs.com/package/autobahn

Activity

  1. ClemensSchneider commented on Jan 16, 2019

    @ClemensSchneider
    Author
  2. filipesilva commented on Jan 22, 2019

    @filipesilva
    Contributor

    Heya, was looking into this error and the error happens in ./node_modules/when/dist/browser/when.js, around line 856.

    What prompts it is indeed the buildOptimizer option, but not actually the Build Optimizer tool itself. Instead, what causes this is an Uglify/Terser option we set in conjunction with Build Optimizer called pure_getters.

    This option affects code removal by signalling that property access has no side effects. We turn this on together with Build Optimizer as part of our suite of advanced optimizations for the smallest bundle size.

    In some cases, like this one, this option can break existing code. It's not the first time that it has happened but it has been rare enough, and the savings significant enough, that we keep this option on.

    You have a couple of options that address this problem right now:

    Whenever we get a report of this happening we reevaluate the current behaviour to see if it's still desirable. I'll bring this up with the team.

  3. ClemensSchneider commented on Jan 22, 2019

    @ClemensSchneider
    Author

    Thanks for investigating!
    I also suspected when to cause the trouble and tried to remove the autobahn module and just add when as import to see if the same error appears. With only when, the issue does not appear.

    Will try to add this case to a separate branch for easier reproduction.

  4. ClemensSchneider commented on Jan 22, 2019

    @ClemensSchneider
    Author

    See https://github.com/ClemensSchneider/angular-buildoptimizer-bug/tree/angular7-whenjs for the same showcase but depending on when only (same version, 3.7.8). With this setup, the issue does not appear.

  5. filipesilva commented on Jan 22, 2019

    @filipesilva
    Contributor

    It might be a usage issue though. I don't know how the when library is used inside autobahn (or it's dependencies). It might not happen with just importing the library, but rather when using it in a certain way.

  6. ClemensSchneider commented on Jan 22, 2019

    @ClemensSchneider
    Author

    Okay, I'll stick to turning off the Build Optimizer for now.
    Would it be possible to expose turning off pure_getters as an option to CLI users? I guess this would introduce too much coupling to the internals though, right..

  7. pkozlowski-opensource commented on Feb 1, 2019

    @pkozlowski-opensource
    Member

    @filipesilva what is the next actionable step here? Should we move it to the CLI repo?

  8. added this to the needsTriage milestone on Mar 19, 2020
  9. added
    freq1: lowOnly reported by a handful of users who observe it rarely
    needs: discussionOn the agenda for team meeting to determine next steps
    featureLabel used to distinguish feature request from other issues
    on May 28, 2020
  10. modified the milestones: needsTriage, Backlog on May 28, 2020
  11. dgp1130 commented on May 28, 2020

    @dgp1130
    Collaborator

    I'll bring this up at the next CLI meeting to see if it is worth supporting adding a pure_getters option to the CLI. Since it modifies runtime behavior, it can break unconforming code, and then an application's only option is to disable buildOptimizer or hack the Webpack config. I'm not sure what our current position on potentially-destructive optimizations is, so we'll need to discuss this a bit.

  12. dgp1130 commented on Jun 4, 2020

    @dgp1130
    Collaborator

    Duplicate of #15761

    We can track further there.

  13. removed
    needs: discussionOn the agenda for team meeting to determine next steps
    on Jun 4, 2020
  14. angular-automatic-lock-bot commented on Jul 5, 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.

  15. locked and limited conversation to collaborators on Jul 5, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Labels

featureLabel used to distinguish feature request from other issuesfreq1: lowOnly reported by a handful of users who observe it rarely

Type

No type

Projects

No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions