Reputation: 3002
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?
Upvotes: 3
Views: 6345
Reputation: 8552
As for me (i am using latest Angular CLI)
impoting zone in main.ts
helps
import { enableProdMode } from '@angular/core';
import { platformBrowserDynamic } from '@angular/platform-browser-dynamic';
// here
import 'zone.js/dist/zone';
import 'rxjs/add/operator/map'
import { AppModule } from './app/app.module';
import { environment } from './environments/environment';
if (environment.production) {
enableProdMode();
}
platformBrowserDynamic().bootstrapModule(AppModule);
Upvotes: 1
Reputation: 4875
Once you have updated to [email protected], make sure you have updated your zone.js@^0.6.6, and I can confirm once you have updated those dependencies zone.js error will disappear. Hopefully this can be helpful!
Upvotes: 1
Reputation: 3025
I changed lite-server to live-server and the error is gone. Besides, with lite-server updates on the app did not cause page refresh, with live-server page refreshes automatically.
Upvotes: 2
Reputation: 202216
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.
Upvotes: 4