3

I'm working on a Angular project, recently updated to Angular 6 from Angular 5.2.10. Before the upgrade everything works fine.

Now, every time I compile my code for production, although there is no errors whatsoever during compile time, I receive this error when running:

ReferenceError: must call super constructor before using |this| in Ti class constructor

The only typescript class that use super is

export class Exception extends Error {
    private _statusCode: number;

    constructor(statusCode: number, type: ExceptionType) {
        super(ExceptionType[type]);
        this._statusCode = statusCode;
    }

    get statusCode(): number {
        return this._statusCode;
    }
}

Simple and plain. ExceptionType is an Enum.

The error is pretty self explanatory, but it seems I did the right thing, because Error class constructor has a single, optional parameter

Error(errorMsg?:string)

and this is called after the 'super' thing.

I'm numb.

Edit: tried the suggestion from comments, not working for me

Edit 2: as @estus pointed out, the error is not in this code but in

class Ei {
            constructor(l, n=Ei.now) {
                this.SchedulerAction = l,
                this.now = n
            }
            schedule(l, n=0, e) {
                return new this.SchedulerAction(this,l).schedule(e, n)
            }
        }
        Ei.now = Date.now ? Date.now : ()=>+new Date;
        class Ti extends Ei {
            constructor(l, n=Ei.now) {
                this.actions = [],
                this.active = !1,
                this.scheduled = void 0
            }
    ...
}

The affected row is

this.actions = []

Which has nothing to do with my code. I'll open a issue on github.

Edit 3: please check https://github.com/angular/angular-cli/issues/7799#issuecomment-386582136

Valerio
  • 3,297
  • 3
  • 27
  • 44
  • `ExceptionType` is a type you are using as value in super. – Fateme Fazli May 08 '18 at 08:02
  • Possible duplicate of [Typescript - Extending Error class](https://stackoverflow.com/questions/41102060/typescript-extending-error-class) – Estus Flask May 08 '18 at 08:11
  • It's still unclear why this error may be triggered. It's not evident that `Ti` class refers to `Exception`. Please, provide http://stackoverflow.com/help/mcve that can replicate the problem. – Estus Flask May 08 '18 at 08:19
  • @fatemefazli, ExceptionType is an Enum, and using ExceptionType[type] return the associated string. – Valerio May 08 '18 at 08:27
  • @estus, I don't know how give you and others here a working example without giving you a full access to repo. Exception class is shared between angular and other server side projects in the same solution. And there is no TI class in source code, I believe that name come from uglyfing. – Valerio May 08 '18 at 08:31
  • The fact that the issue is only on production, could be caused to uglyfing? – Valerio May 08 '18 at 08:36
  • You can click on the place in where the error happens in call stack to check where the error happens. You can likely recognize classes even if they are uglified. This may be caused either by minification or by AOT, although I don't see how any of them can affect the code that was posted, so it's likely not the case. Try to disable minification in production build and see what happens. Even if it's 6.0.0 bug, you'll need to provide a way to replicate it to post it in Angular issues. – Estus Flask May 08 '18 at 08:56
  • @estus, thanks, you pointed to the right direction. – Valerio May 08 '18 at 09:42

0 Answers0