angular-cli: Error with Angular Build Optimizer and ES2015 target

Bug Report or Feature Request (mark with an x)

  • bug report -> please search issues before submitting

Versions.

macOS Angular CLI 1.5.0-beta.1 Angular 4.4.3 TS 2.3.4

Repro steps.

In a new cli app set the target to es2015. This works with ng serve --prod and ng build --prod. Run ng serve --prod --build-optimizer or ng build --prod --build-optimizer and there will be a runtime error on application start up.

main.39bafd92ae514fbdcd5b.bundle.js:1 Uncaught ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
    at Be (main.39bafd92ae514fbdcd5b.bundle.js:1)
    at Object.<anonymous> (main.39bafd92ae514fbdcd5b.bundle.js:1)
    at Object.nkKW (main.39bafd92ae514fbdcd5b.bundle.js:1)
    at n (inline.36c967fef94b0262187c.bundle.js:1)
    at Object.cDNt (main.39bafd92ae514fbdcd5b.bundle.js:1)
    at n (inline.36c967fef94b0262187c.bundle.js:1)
    at Object.0 (main.39bafd92ae514fbdcd5b.bundle.js:1)
    at n (inline.36c967fef94b0262187c.bundle.js:1)
    at window.webpackJsonp (inline.36c967fef94b0262187c.bundle.js:1)
    at main.39bafd92ae514fbdcd5b.bundle.js:1

From the main bundle

class Be extends Ve {
  constructor(e) {
    // missing super call here
  }
  
  toString() {
    return `InjectionToken ${this._desc}`
  }
}
...

In the compiled class there is on super call on a derived class. When the build optimizer is not used the super call is there. The TS application code has no extended bases classes so I’m guessing its coming from the vendors but unfortunately something is broken with the source mapping for me with es2015 as well.

About this issue

  • Original URL
  • State: closed
  • Created 7 years ago
  • Comments: 20 (10 by maintainers)

Commits related to this issue

Most upvoted comments

@filipesilva This bug reproduce when use angular v6 , cli v6, and rxjs v6.1.0 to build target es2015. The error is Uncaught ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor at rxjs AsyncScheduler.js .

Heya, we are aware this is still broken. The current tracking issue for this problem is https://github.com/angular/devkit/issues/816.

Still seeing his on Angular 6.0.1:

main.0a1fe70472d685fb5aba.js:1 Uncaught ReferenceError: Must call super constructor in derived class before accessing 'this' or returning from derived constructor
    at new <anonymous> (main.0a1fe70472d685fb5aba.js:1)
    at Object.zUnb (main.0a1fe70472d685fb5aba.js:1)
    at p (runtime.6afe30102d8fe7337431.js:1)
    at Object.10 (main.0a1fe70472d685fb5aba.js:1)
    at p (runtime.6afe30102d8fe7337431.js:1)
    at n (runtime.6afe30102d8fe7337431.js:1)
    at Array.e [as push] (runtime.6afe30102d8fe7337431.js:1)
    at main.0a1fe70472d685fb5aba.js:1

When expanding the obfuscated code, it looks like this:

        const L = new class extends class { // <--- Why is this "new class extends class" ??????
            constructor(e=null) {
                this.modifiers = e, // <-- Why is this one okay ?  No call to super() !!
                e || (this.modifiers = [])
            }
            hasModifier(e) {
                return -1 !== this.modifiers.indexOf(e)
            }
        }
        {
            constructor(e, t=null) {
                this.name = e   // <---  OFFENDING LINE, there is a super() missing!!
            }
            visitType(e, t) {
                return e.visitBuiltinType(this, t)
            }
        }

Had to switch off build-optimizer for the time being.