angular: TypeError: Cannot read property 'zone' of null (touch)

  • *I’m submitting a … * [X] bug report [ ] feature request [ ] support request => Please do not submit support request here, see note at the top of this template.
  • Do you want to request a feature or report a bug? See above
  • What is the current behavior? Touch events now function (see: https://github.com/angular/angular/issues/6993) but also output a number of exceptions: Uncaught TypeError: Cannot read property 'zone' of null
  • If the current behavior is a bug, please provide the steps to reproduce and if possible a minimal demo of the problem via See http://plnkr.co/edit/53gbav4XuvWrDt6oEiYO?p=preview Swipe left on title with console open
  • What is the expected behavior? touch function is called without exceptions
  • Please tell us about your environment:
  • Angular version: 2.0.0-beta.10
  • Browser: [Chrome 48 ]
  • Language: [TypeScript]

About this issue

  • Original URL
  • State: closed
  • Created 8 years ago
  • Reactions: 17
  • Comments: 51 (15 by maintainers)

Most upvoted comments

i confirmed what @manekinekko sees. it works fine with live-server, but not with lite-server (which uses browser-sync).

here is what i get with bs

image

im getting same error just using node server to serve a SPA

using angular2 = 2.0.0-beta.11

screen shot 2016-03-20 at 1 43 03 am

Same here - beta-11 now gives a similar error in more places and stops the app functioning:

TypeError: Cannot read property 'zone' of undefined

I got a similar error after updating to beta10, app won’t bootstrap: angular2-polyfills.js:142 Uncaught TypeError: Cannot read property 'zone' of undefined. Here’s the line 142 from angular2-polyfills: task.zone.cancelTask(task);

beta-12 seems to be running well for me 👍

I checked right now on our main project and it seems to be resolved with beta.12.

Still happens for me, when running a compiled app on a simple node server, using angular2@2.0.0-beta.10 to beta.13 + zone.js@0.6.6. Works fine with angular2@2.0.0-beta.9 + zone.js@0.6.6.

Getting Uncaught TypeError: Cannot read property 'fork' of undefined on ng_zone_impl.js (source map) here:

var NgZoneImpl = (function () {
    function NgZoneImpl(_a) {
        var trace = _a.trace, onEnter = _a.onEnter, onLeave = _a.onLeave, setMicrotask = _a.setMicrotask, setMacrotask = _a.setMacrotask, onError = _a.onError;
        this.name = 'angular';
        this.properties = { 'isAngularZone': true };
        this.onEnter = onEnter;
        this.onLeave = onLeave;
        this.setMicrotask = setMicrotask;
        this.setMacrotask = setMacrotask;
        this.onError = onError;
        if (lang_1.global.Zone) {
            this.outer = this.inner = Zone.current;
            if (Zone['wtfZoneSpec']) {
                this.inner = this.inner.fork(Zone['wtfZoneSpec']);
            }
            if (trace) {
                this.inner = this.inner.fork(Zone['longStackTraceZoneSpec']); // <== FAILS HERE (inner and outer are undefined)
            }

I think it all comes down to socket.io, since I don’t use any server-reloading-module that depends on browser-sync and I’ve got the same problem.

In another project, where I use ws instead, beta11 is working just fine.

Getting similar error using Ionic 2 beta 3 with Angular 2 beta 11:

browser_adapter.js:76 Error: Uncaught (in promise): TypeError: Cannot read property 'zone' of undefined
    at resolvePromise (angular2-polyfills.js:534)
    at angular2-polyfills.js:570
    at ZoneDelegate.invokeTask (angular2-polyfills.js:355)
    at Object.NgZoneImpl.inner.inner.fork.onInvokeTask (ng_zone_impl.js:35)
    at ZoneDelegate.invokeTask (angular2-polyfills.js:354)
    at Zone.runTask (angular2-polyfills.js:254)
    at drainMicroTaskQueue (angular2-polyfills.js:473)
    at XMLHttpRequest.ZoneTask.invoke (angular2-polyfills.js:425)

Edit: Confirming that downgrading to Beta 9 fixes the issue.

It happens with the pre-built packages in the plunkr so I don’t think typings are going to have any effect one way or the other.

@cpiock this is not related to …‘zone’ of null! i guess your problem is something on path/filesystem!

I think that this issue is somehow related to browsersync. Because when using the Angular 2 CLI, everything works fine.

image

Update to Beta 12 and the Zone.js to 0.6.6

I just reset my npm install with beta 12 and dependencies, and it works all good !

There’s no mention to it.

I created a live-reloading-server-module-thing that doesn’t depend on socket.io, so it’s working just fine. For those interested, feel free to check it out.

Browsersync author here, please see my comment:

https://github.com/angular/angular/issues/7705#issuecomment-200019429

The issue lies with how socket.io is calling clearTimeout - something the zone.js will be intercepting

recompiles may be slow on TypeScript 1.7. There was a bug with it. Go to 1.8.x

Seems https://github.com/angular/zone.js/commit/5783663a80926b6154d5c900a3a5645be7bd53bb fixed this. Temp workaround is patching angular2-polyfills.js the with:

var clearNative = utils_1.patchMethod(window, cancelName, function (delegate) { return function (self, args) {
    var task = args[0];
    if (task && typeof task.type == 'string') {
        task.zone.cancelTask(task);
    } else {
        delegate.apply(window, args);
    }
}; });