angular-cli icon indicating copy to clipboard operation
angular-cli copied to clipboard

Uncaught TypeError: Cannot read property 'apply' of undefined on new install

Open iainplimmer opened this issue 9 years ago • 103 comments

Bug Report or Feature Request (mark with an x)

  • [x] bug report -> please search issues before submitting
  • [ ] feature request

Versions.

@angular/cli: 1.0.0 node: 6.9.5 os: darwin x64 @angular/common: 4.0.3 @angular/compiler: 4.0.3 @angular/core: 4.0.3 @angular/forms: 4.0.3 @angular/http: 4.0.3 @angular/platform-browser: 4.0.3 @angular/platform-browser-dynamic: 4.0.3 @angular/router: 4.0.3 @angular/cli: 1.0.0 @angular/compiler-cli: 4.0.3

Repro steps.

npm install -g @angular/cli ng new projectname cd projectname ng serve --> Browse to localhost:4200 in Chrome

The log given by the failure.

When you first open the browser you get the following message: Angular is running in the development mode. Call enableProdMode() to enable the production mode.

Then the error Uncaught TypeError: Cannot read property 'apply' of undefined at XMLHttpRequest.desc.get [as ontimeout] (zone.js:1265) at XHRLocalObject.AbstractXHRObject._cleanup (abstract-xhr.js:149) at XMLHttpRequest.xhr.onreadystatechange (abstract-xhr.js:125) at XMLHttpRequest.wrapFn (zone.js:1230) at ZoneDelegate.invokeTask (zone.js:398) at Zone.runTask (zone.js:165) at XMLHttpRequest.ZoneTask.invoke (zone.js:460)

Desired functionality.

Bug fix or the ability to work out why it's not actually working, i've cleaned the NPM cache, reinstalled with -g and still get an error.

Mention any other details that might be useful.

iainplimmer avatar Apr 22 '17 07:04 iainplimmer

Same here. Had t downgrade to zone.js 0.8.5 as @JoseIgor mentioned.

benjaminu avatar Apr 22 '17 21:04 benjaminu

Freeze to 0.8.5 helped , thanks @JoseIgor

rubenCodeforges avatar Apr 22 '17 21:04 rubenCodeforges

Downgraded zone and worked npm install [email protected] --save ng server

tanvir-ux avatar Apr 22 '17 22:04 tanvir-ux

Angular-cli generated app subsequently upgraded (via npm-check-updates - ncu -a ) to latest packages, including angular 4.0.3 and zone.js 0.8.8 fails as previously described.

downgrading from zone.js 0.8.8 to zone.js 0.8.5 - error disappears during ng serve --open

downgrading from zone.js 0.8.8 to zone.js 0.8.6 - error disappears during ng serve --open

downgrading from zone.js 0.8.8 to zone.js 0.8.7 - error disappears during ng serve --open

conclusion: angular 4.0.3 and zone.js 0.8.8 are not compatible.

fmorriso avatar Apr 22 '17 23:04 fmorriso

same error, with a fresh project... Before: image

Then: 1.edit package.json , check zone.js change version from 0.8.8 to 0.8.5, and save "zone.js": "0.8.5" 2.install the specific version npm install [email protected] 3.if everything going well, do npm start 5.Go to your browser localhost:4200 , and (firefox) javascript console don't show the error. So ...are we stack on this version?

spartandeveloper avatar Apr 23 '17 06:04 spartandeveloper

Run the following command in your project folder: npm install [email protected] --save http://stackoverflow.com/questions/43556422/angular-2-typeerror-cannot-read-property-apply-of-undefined

truongvanninh avatar Apr 23 '17 08:04 truongvanninh

but it just works fine in firefox.

leejoohan avatar Apr 23 '17 09:04 leejoohan

How do you upgrade to 4.0.3 ? I'm having the same issues on 4.0.0 and zone.js 0.8.4

ghost avatar Apr 23 '17 09:04 ghost

Same here.. after upgrading to v0.8.8 capture

irowbin avatar Apr 23 '17 09:04 irowbin

The way I upgrade Angular versions (e.g., 4.0.0 to 4.0.3) is to use the (previously installed on my machine) npm-check-updates command:

  1. cd to the directory where package.json is located.
  2. ncu -a
  3. npm install I did this recently and discovered that Angular 4.0.3 works with zone.js 0.8.7 and below but not with zone.js 0.8.8.

FYI: when I create a new project with Angular-cli, I always specify the --skip-install switch as in: ng new something --skip-install --routing --style=css cd something ncu -a npm i

fmorriso avatar Apr 23 '17 10:04 fmorriso

+1

yaroslavert avatar Apr 23 '17 11:04 yaroslavert

npm install [email protected] --save

yaroslavert avatar Apr 23 '17 11:04 yaroslavert

Thanks! it works with zone.js 0.8.4 :) :)

nicosaliagas avatar Apr 23 '17 12:04 nicosaliagas

with [email protected] the problem disappeared. Removes the node_modules folder and runs the npm install command again.

hectorMurillo avatar Apr 23 '17 19:04 hectorMurillo

Same situation/solution here: zone 0.8.5 worked for me!

jonathantorrens425 avatar Apr 23 '17 20:04 jonathantorrens425

Just a reminder that Angular 4.0.3 works fine with [email protected], as well as 0.8.5 and 0.8.6.

Only zone.js 0.8.8 has the problem of "does not play nice with others" (Angular 4.0.3 to be specific), so do not feel like you have to downgrade all the way back to 0.8.5 as some have suggested. That's a bit extreme.

fmorriso avatar Apr 23 '17 22:04 fmorriso

Saw this issue today and the below on-liner fixes for me.

npm install [email protected] --save 

syscools avatar Apr 24 '17 05:04 syscools

Same here, works in 0.8.7

nlgi avatar Apr 24 '17 08:04 nlgi

I tried that, not even fresh new app is not working. I tried couple of times to remove angular/cli and angular-cli globally, multiple times local node_modules. Tried to run ng serve globally and locally same error in chromium, but older project runs there fine. I think I need to run it in chromium as some of my target devices are build on it.

Also I noticed that npm show zone.js version shows globally installed version 0.8.8 (not obvious for me npm noob). Tried to uninstall it and clean cache, but another lookup and 0.8.8 still there, at least in some deeper cache? Could not find it in .npm/ nor in .nvm/versions/node/v7.5.0/node_packages. And npm list | grep zone prints [email protected] as angular/clie dep. and [email protected] as project dep. (my fixed version). The older working project has these the same.

I even tried to copy&paste node_modules from thw working project and install rest of the deps. Also I tried to copy&paste dist/ of zone.js unproven fix. - same error.

I don't know what to do next maybe complete reinstall node+npm+nvm and start from clean slate, but it seems rather extreme.

sangecz avatar Apr 24 '17 10:04 sangecz

@sangecz What version you did you select in "package.json" ? if zone.js is not version 0.8.8, npm install again should be fine.

nui-tech avatar Apr 24 '17 10:04 nui-tech