Angular-HMR icon indicating copy to clipboard operation
Angular-HMR copied to clipboard

[HMR] TypeError: Cannot read property 'has' of undefined

Open villesau opened this issue 9 years ago • 6 comments

I tried to apply the angular-HMR to the existing project and got this error:

[HMR] TypeError: Cannot read property 'has' of undefined at HotAngular.reloadState (http://localhost:8080/assets/style-guide.js:61911:26) at module.exports as directive at Object. (http://localhost:8080/assets/style-guide.js:67077:63) at webpack_require (http://localhost:8080/assets/style-guide.js:521:30) at hotApply (http://localhost:8080/assets/style-guide.js:476:14) at hotUpdateDownloaded (http://localhost:8080/assets/style-guide.js:269:13) at hotAddUpdateChunk (http://localhost:8080/assets/style-guide.js:249:13) at webpackHotUpdateCallback (http://localhost:8080/assets/style-guide.js:5:12) at http://localhost:8080/assets/0.b36e9a53c6b398f686b1.hot-update.js:1:1

Any advices, or is it a bug? The library seems to understand the angular directives and logs them into console, so i guess there is just a small bug somewhere.

villesau avatar Jan 13 '16 09:01 villesau

the actual line it crashes is the last one of these:

HotAngular.prototype.reloadState = function() {
  var elm = angular.element(document.querySelector('[ng-app]'));
  if (elm) {
      if (elm.injector().has('$state')) {

So elem.injector() returns undefined.

villesau avatar Jan 13 '16 10:01 villesau

i have a fork where i changed .querySelector('[ng-app]') to .querySelector('body') which fixed the problem in my case. I could make a pull request of it but this repo seems to live it's own life i think.. The current version of the repo seems to be pretty broken so i didn't start to fix that, but the one is in NPM.

https://github.com/villesau/Angular-HMR

villesau avatar Jan 13 '16 11:01 villesau

Hey @villesau,

The previous release would be a bit behind, if You make a pull request I can fix up the rest thats broken, can always take it back to this commit https://github.com/yargalot/Angular-HMR/commit/08a5a09f548a8e7a907c1345a4094dbb9daf501d and then throw up an update for you. Happy to do that, didnt realise people were using it ;D

yargalot avatar Jan 14 '16 11:01 yargalot

But yeh, I imagine your manually bootstrapping the app instead of using ng-app? can use the body / html as a fallback if ng-app doesnt exist

yargalot avatar Jan 14 '16 11:01 yargalot

I've forked this project and added configuration to select app root element. https://github.com/vitaliy-bobrov/angular-hot-loader

vitaliy-bobrov avatar Jan 09 '17 08:01 vitaliy-bobrov

Is there any fix for that??

YonathanB avatar Dec 26 '18 14:12 YonathanB