Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
CaptainCodeman opened this issue Mar 17, 2016 · 51 comments
Closed

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

CaptainCodeman opened this issue Mar 17, 2016 · 51 comments

Comments

@CaptainCodeman
Copy link

  • *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: [BETA-6] Gesture (swipeleft) event makes Zone throw Maximum call size exceeded #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]
@biiiipy
Copy link

biiiipy commented Mar 18, 2016

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);

@PatrickJS
Copy link
Member

@biiiipy as a workaround add this to your typings.json and typings install
typings.json

{
  "dependencies": {
    "zone.js": "github:gdi2290/typed-zone.js/lib/zone.d.ts#225aa313388bdf78b18ed9f0b29f93a395146229"
  },
  "devDependencies": {},
  "ambientDependencies": {
    "zone.js": "github:gdi2290/typed-zone.js/lib/zone.d.ts#225aa313388bdf78b18ed9f0b29f93a395146229"
  }
}

@msklvsk
Copy link

msklvsk commented Mar 18, 2016

@gdi2290, can a typing fix a runtime error? Still having same exception.

@pitops
Copy link

pitops commented Mar 18, 2016

tried this, having same problem, @gdi2290 your fix does not seem to fix the issue.

@CaptainCodeman
Copy link
Author

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.

@xbtequila
Copy link

Got the same exception when using websockets/socket.io.

@chrisnicola
Copy link

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.

@CaptainCodeman
Copy link
Author

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

TypeError: Cannot read property 'zone' of undefined

@todoubaba
Copy link
Contributor

Same here, stacktrace:

Uncaught TypeError: Cannot read property 'zone' of null
(anonymous function) @ browser_platform_location.ts:58
clearTimeout @ VM9380:3
n @ tether.min.js:1

@ganeshkbhat
Copy link

downgrading to beta 9 resolves the issue. not related to typings. Error pointing to angular2-polyfills: 142 source:

var clearNative = utils_1.patchMethod(window, cancelName, function () { return function (self, args) {
            var task = args[0];
            task.zone.cancelTask(task); <<<<===
 }; });

@manekinekko
Copy link
Contributor

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

image

@johnpapa
Copy link
Contributor

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

@caninojories
Copy link

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

@zewa666
Copy link

zewa666 commented Mar 19, 2016

Oh man, each update a new challenge 😒

in the meantime surrounding the mentioned section with an if clause checking for whether the task is defined fixes the problem temporary.

Agree with @johnpapa and @manekinekko, seems to be related to BrowserSync

EDIT:
sry nope, fix doesn't help, still getting issues :(

@antoineol
Copy link

I'm getting the same issue with systemjs-hot-reloader (the error goes away when disabling hot reloading). As far as I know, it is not using BrowserSync, but also provides hot reloading. In case it can help to point the cause.

@panjiesw
Copy link

Might be useful for those who want to use 2.0.0-beta.11

I am using live-server instead of lite-server/browser-sync for now, until this is resolved. It works well with similar watch files and reload, just like lite-server.

@belevtsev
Copy link

For me live-server doesn't work. in 2.0.0-beta.11

@johnpapa
Copy link
Contributor

The angular team is aware of the issue and are working on a fix. Keep the reports coming as more and new information is helpful in diagnosing it.

For now, you can either use your server of choice with beta 11 and you may see the error in the console or go back to beta 9. I am using beta 11 for now as the error msg doesnt appear to cause any problems with my app at this time.

@todoubaba
Copy link
Contributor

Seems angular/zone.js@5783663 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);
    }
}; });

@PatrickJS
Copy link
Member

here's the workaround if you build from source
PatrickJS/PatrickJS-starter@1661e4c

@sethflowers
Copy link

+1

@andycwk
Copy link

andycwk commented Mar 21, 2016

I'm having the same issue, but I'm not running any form of live reload software, think that's just a red herring or linked to how browsersync is doing it's thing!

In my case I'm trying to boot intercom.js, I also tried using zone.runOutsideAngular() in an attempt to resolve!

The error appears in the console as Intercom drops it's UI overlay on the screen.

Also, there's a lovely debugger statement @ line 388 of https://code.angularjs.org/2.0.0-beta.11/angular2-polyfills.js :|

constructor(
    private userService: UserService,
    private router: Router) {
    this.userService.profile$.subscribe(profile => profile ? this.boot(profile) : this.shutdown());
    this.router.subscribe(_ => window.Intercom('update'));
    });
}

private boot(profile: UserProfile) {
        window.Intercom('boot', {
            app_id: "xxxxx",
            user_id: profile.userId,
            name: profile.fullName(),
            email: profile.emailAddress
        });
}

@asotog
Copy link

asotog commented Mar 21, 2016

same here, updated to latest beta release and getting the same error, im building from npm modules,
angular2-polyfills.js:142 Uncaught TypeError: Cannot read property 'zone' of undefined

when getting back to beta 9, it disappears

@MaxGeissel
Copy link

Same here with socket.io. Any ideas?

@johnpapa
Copy link
Contributor

This issue has also affected lite-server and its ability to refresh the browser using BrowserSync with sockets. johnpapa/lite-server#56 (comment)

I recommend staying on beta 9 if you need this feature until this is resolved

cc // @naomiblack @wardbell

@CaptainCodeman
Copy link
Author

I think the issue of browser syncing while developing is just a symptom - something that happens to trigger the issue.

It still also happens with a production build for me.

@johnpapa
Copy link
Contributor

yes, the issue is with the new version of zones and the team is working on a fix.

@CarlosAmaral
Copy link

Even with BrowserSync, it takes forever to recompile if you have made a couple of changes. Might be due to my computer's specs.

@johnpapa
Copy link
Contributor

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

@CarlosAmaral
Copy link

@johnpapa It's 10x faster. Thanks!

@amcdnl
Copy link
Contributor

amcdnl commented Mar 22, 2016

@CarlosAmaral i switched off of browsersync this week to nginx to fight some of these perf related issues.

@shakyShane
Copy link

Browsersync author here, please see my comment:

#7705 (comment)

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

@Yagger
Copy link

Yagger commented Mar 23, 2016

Weird fact. 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.

@vsDizzy
Copy link

vsDizzy commented Mar 23, 2016

Including "angular2-polyfills.min.js" breaks browser-sync, so the page could not be auto-reloaded.

@CarlosAmaral
Copy link

@Yagger npm run lite ?

@otabekgb
Copy link

Does anybody know if this issue resolve on beta.12?

@ericmdantas
Copy link
Contributor

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.

@meriturva
Copy link

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

@tiagoroldao
Copy link

I believe this was a fix on zone.js, which is why you wouldn't see it in the changelog: angular/zone.js#276

@ericmdantas
Copy link
Contributor

Zone doesn't seem to have a changelog, though 😞

@aboudard
Copy link

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

@asrullat
Copy link

i can confirm that - i had that issue when i was using ng2 beta 11 with browsersync. now everything works fine. big thx

@CaptainCodeman
Copy link
Author

beta-12 seems to be running well for me 👍

@qheolet
Copy link

qheolet commented Mar 28, 2016

Update to Beta 12 and the Zone.js to 0.6.6

@meriturva
Copy link

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

@yoava
Copy link

yoava commented Apr 12, 2016

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)
            }

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Sep 8, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests