ERROR TypeError: Class constructor EventEmitter_ cannot be invoked without 'new'

Viewed 1130

After upgrading to Angular 10, I am getting following error for some components -

ERROR TypeError: Class constructor EventEmitter_ cannot be invoked without 'new'
    at new ZoneAwareEventEmitter (index.js:34)
    at new GridComponent (index.js:6167)
    at createClass (core.js:21921)
    at createDirectiveInstance (core.js:21790)
    at createViewNodes (core.js:30281)
    at callViewAction (core.js:30597)
    at execComponentViewsAction (core.js:30516)
    at createViewNodes (core.js:30309)
    at callViewAction (core.js:30597)
    at execComponentViewsAction (core.js:30516)

The code that is causing this issue -

import { EventEmitter } from "@angular/core";

export class ZoneAwareEventEmitter extends EventEmitter {
    constructor(ngZone, isAsync = false) {
        super(isAsync);
        this.ngZone = ngZone;
    }
}

Am I missing something?

Thanks in advance for the help!

1 Answers

Add this to Webpack config:

resolve: {
    mainFields: ['es2015', 'browser', 'module', 'main']
},

The problem occurs in Webpack builds in projects using Kendo Angular Grid. The default Webpack configuration resolves the fesm5 module from node_modules/@progress/kendo-angular-grid, which tries to extend the EventEmitter class using es5 and results in the error. Changing the mainFields property of resolve inside Webpack config to prioritize es2015 modules fixed this for me.

Related