rdehuyss / homeassistant-lovelace-google-calendar-card

A calendar card for Home Assistant using Lovelace
91 stars 14 forks source link

Uncaught ReferenceError: moment is not defined #23

Closed scstraus closed 4 years ago

scstraus commented 5 years ago

Sometimes randomly I get this error in the log and Calendar card decides not to load. Any idea why?

https://MYHOST:8123/local/custom_ui/calendar-card/calendar-card.js?v=1.0.1:10:7 Uncaught ReferenceError: moment is not defined

A lot of times it works fine, but sometimes it does that.

HACee commented 5 years ago

I didn't ever get this error, but just upgraded to 0.86.1 and have got it quite a few times now.

ozrex75 commented 5 years ago

Me too after upgrading to 0.86.1

IIIdefconIII commented 5 years ago

Same

since 0.86.1 sometimes the card dissapears from lovelace ui

gregcsw commented 5 years ago

Having the same issue since 0.86.1

YoinkZed commented 5 years ago

Me too. Happened as well after the 86.1 update.

yosilevy commented 5 years ago

It's not random for me. I have calendar card on a view that is not the first one. If I open the GUI it never happens since moment loads before the card since to view the card I need to go to another view. If I refresh the browser when I'm in the view that has the calendar card it ALWAYS fails now.

IIIdefconIII commented 5 years ago

is this still maintaned?

IIIdefconIII commented 5 years ago

where do you guys have the js file? i just changed it from /local to url: /local/custom_ui/calendar-card/calendar-card.js?v=4 and it seems to have non more issues, for now

YoinkZed commented 5 years ago

where do you guys have the js file? i just changed it from /local to url: /local/custom_ui/calendar-card/calendar-card.js?v=4 and it seems to have non more issues, for now

Hi def, I have it stored the same place as where you have changed it to: url: /local/custom_ui/calendar-card/calendar-card.js?v=1.0.1

The thing I don't understand is your version? I never saw an update with my custom updater and it doesn't look like the js file has been updated lately here on github?

IIIdefconIII commented 5 years ago

just to made sure i never messed up i have put a random number on it, you may try aswell

YoinkZed commented 5 years ago

Yeah why not. Will give it a try. Just weird that if I set another page or move the calendar card to another tab, then I don't get the error, because the moment file will be loaded before it gets called by the calendar card...

yosilevy commented 5 years ago

That's still my problem. Refreshing page with calendar-card on it never works.

yosilevy commented 5 years ago

Solved it (brute force). Change the set hass function in to these 2 funcs.

  set hass(hass) {
    this._hass = hass;

    if (!this.content) {
      const card = document.createElement('ha-card');
      card.header = this.config.name;
      this.content = document.createElement('div');
      this.content.style.padding = '0 16px 16px';
      card.appendChild(this.content);
      this.appendChild(card);
    }

    this.init();
  }

  init() {
    if(typeof(moment) == "undefined") {
      setTimeout(() => this.init(), 200);
      return;
    }

    moment.locale(this._hass.language);
    this
      .getAllEvents(this.config.entities)
      .then(events => this.updateHtmlIfNecessary(events))
      .catch(error => console.log('error', error));
  }
IIIdefconIII commented 5 years ago

Do you have moments js higher then the card module? I do...

On Wed, 30 Jan 2019, 21:58 YoinkZed <notifications@github.com wrote:

Yeah why not. Will give it a try. Just weird that if I set another page or move the calendar card to another tab, then I don't get the error, because the moment file will be loaded before it gets called by the calendar card...

— You are receiving this because you commented. Reply to this email directly, view it on GitHub https://github.com/rdehuyss/homeassistant-lovelace-google-calendar-card/issues/23#issuecomment-459106228, or mute the thread https://github.com/notifications/unsubscribe-auth/AJdU24GYbBoXFLU7zuGaH66vE6elIO95ks5vIgd5gaJpZM4aJIKp .

YoinkZed commented 5 years ago

Where have you 'downloaded' the moments file from? I think I still use the one that is on this git repo/or the one that are in the link.

IIIdefconIII commented 5 years ago

set hass(hass) {

In what file did you made the change, i tought my problems were away but still having the issue, or upload the file file? thnx

yosilevy commented 5 years ago

In the calendar-card file. Code is above and there's also a pull request pending with my change. You can just copy it.

bouwew commented 5 years ago

@yosilevy, thanks! I've used your solution successfully to solve this error in another HA-card.

scstraus commented 4 years ago

This cars s is no longer supported so I’m closing