question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

Build Optimizer too aggressive, breaking some of our application code

See original GitHub issue

Versions

1.5.0 (ejected configuration)

Repro steps

  1. Include in module.rules:
                {
                    test: /(\.ngfactory\.js|\.ngstyle\.js|\.ts)$/,
                    use: [
                        {
                            loader: '@angular-devkit/build-optimizer/webpack-loader',
                            options: {
                                sourceMap: true
                            }
                        },
                        '@ngtools/webpack'
                    ]
                },

Step 2: Write code in a method for a component like this:

private instrumentCreateMenuImpression() {
        const params: InstrumentationParams = {};
        params[InstrumentationParam.ItemCount] = this.items ? this.items.length.toString() : '0';
        params[InstrumentationParam.RenderSize] = this.createLinks ? this.createLinks.length.toString() : '0';
        params[InstrumentationParam.Distribution] = this.createLinks
            ? this.createLinks.map(link => link.workload.Id).reduce((prevVal, currVal, index) => prevVal + (index === 0 ? '' : ';') + currVal, '')
            : '';

        const metrics = [
            KnownInstrumentationEvents.CreateMenuImpression,
            `${KnownInstrumentationEvents.CreateMenuImpression}.${this.createLinks.length}`
        ];
        this.instrumentationService.generateImpressionEvent(KnownInstrumentationEvents.CreateMenuImpression, null, params, metrics).record();
}

Step 3: Observe build optimizer output:

CreateMenuComponent.prototype.instrumentCreateMenuImpression = function () {
    var params = /*@__PURE__*/ (function () {
            var params = {};
            params[instrumentation_service["a" /* InstrumentationParam */].ItemCount] = this.items ? this.items.length.toString() : '0';
            params[instrumentation_service["a" /* InstrumentationParam */].RenderSize] = this.createLinks ? this.createLinks.length.toString() : '0';
            params[instrumentation_service["a" /* InstrumentationParam */].Distribution] = this.createLinks
                ? this.createLinks.map(function (link) { return link.workload.Id; }).reduce(function (prevVal, currVal, index) { return prevVal + (index === 0 ? '' : ';') + currVal; }, '')
                : '';
            return params;
        })();
        var metrics = [
            instrumentation_service["e" /* KnownInstrumentationEvents */].CreateMenuImpression,
            instrumentation_service["e" /* KnownInstrumentationEvents */].CreateMenuImpression + "." + this.createLinks.length
        ];
        this.instrumentationService.generateImpressionEvent(instrumentation_service["e" /* KnownInstrumentationEvents */].CreateMenuImpression, null, params, metrics).record();
}

Observed behavior

An exception is thrown: ‘Cannot read propery ‘items’ of undefined’

Desired behavior

Why is params changing structure? I would expect the params object to remain an object.

Mention any other details that might be useful (optional)

Angular 5.0.1 Webpack 3.8.1 TypeScript 2.4.2

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Reactions:1
  • Comments:6 (2 by maintainers)

github_iconTop GitHub Comments

1reaction
hanslcommented, Nov 17, 2017

This seems like an aggressive purify change. Definitely something we should look at.

0reactions
angular-automatic-lock-bot[bot]commented, Sep 7, 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.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Fixing Overly Aggressive Optimization with Terser | by Omri Lavi
This short article describes the error and the investigation process that led us to the solution.
Read more >
Front-End Performance 2021: Build Optimizations
In general, most performance issues come from the initial time to bootstrap the app. So, what's the best way to code-split aggressively, but...
Read more >
Issue 21074: Too aggressive constant folding - Python tracker
The redesigned peephole optimizer in PY3 improves constant folding. Limiting this would be a step back. Plus you can get the same behavior...
Read more >
Optimize Options (Using the GNU Compiler Collection (GCC))
Without any optimization option, the compiler's goal is to reduce the cost of compilation and to make debugging produce the expected results.
Read more >
Using the Closure Compiler - ADVANCED_OPTIMIZATIONS
The Closure compiler is an amazing tool for optimizing JavaScript. ... your code these assumptions may turn out to break your application, ...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found