Search code examples
angularzone

Angular 2 after update I get this error: Cannot read property 'zone' of undefined


I just updated angular 2 from beta 9 to beta 11 (or beta 10) and now I get this error in console: Uncaught TypeError: Cannot read property 'zone' of undefined in angular2-polyfills.js:142 without changing anything to code.

The line in angular2-polyfills.js:142 where console report the error is:

task.zone.cancelTask(task);

I am using plain js.

In index.html I include this 4 js files:

<script src="libs/es6-shim/es6-shim.min.js"></script>
<script src="libs/angular/2.0.0-beta.11/angular2-polyfills.js"></script>
<script src="libs/angular/2.0.0-beta.11/Rx.umd.js"></script>
<script src="libs/angular/2.0.0-beta.11/angular2-all.umd.js"></script>

And all ngZone related code that I use is to make a method of a class accesible from external js.

window.PushService = {
            onCallFromOutside: this.onCallFromOutside.bind(this),
            zone: _ngZone
        };

Also I try to comment all code where I use ngZone and the error is still here.

What is related to and how can I fix this error?


Solution

  • It seems that there are some problems on beta11 regarding Zones. See the message on the angular.io website (https://angular.io/docs/ts/latest/):

    The current beta.11 release has known bugs relating to significant changes to the zones subsystem. All apps will report an error to the console:

    Uncaught TypeError: Cannot read property 'zone' of undefined
    

    The app will run unimpeded but it is disconcerting. We hope to have this and other bugs repaired by beta.12. Thanks for your patience.