commenthol / date-holidays

worldwide holidays
https://commenthol.github.io/date-holidays/
Other
906 stars 234 forks source link

TypeError: Cannot convert undefined or null to object #386

Closed SSANSH closed 1 year ago

SSANSH commented 1 year ago
var Holidays = require('date-holidays')
// or using a new instance
hd = new Holidays('JP');
console.log(hd.getHolidays(2020));

Following codes failed on lastest version of date-holidays@3.16.12 . its works with the version "date-holidays@2.1.1", do you know why?

/node_modules/astronomia/lib/planetposition.cjs:19
  Object.keys(series).forEach((x) => {
         ^

TypeError: Cannot convert undefined or null to object
    at Function.keys (<anonymous>)
    at sum (/node_modules/astronomia/lib/planetposition.cjs:19:10)
    at Planet.position (/node_modules/astronomia/lib/planetposition.cjs:96:38)
    at trueVSOP87 (/node_modules/astronomia/lib/solar.cjs:161:36)
    at Object.apparentVSOP87 (/node_modules/astronomia/lib/solar.cjs:189:29)
    at eq2 (/node_modules/astronomia/lib/solstice.cjs:255:32)
    at longitude (/node_modules/astronomia/lib/solstice.cjs:238:10)
    at Object.march2 (/node_modules/astronomia/lib/solstice.cjs:162:10)
    at Equinox.inYear (/node_modules/date-holidays-parser/lib/Equinox.cjs:29:35)
    at /node_modules/date-holidays-parser/lib/DateFn.cjs:43:12
SSANSH commented 1 year ago

` 12845a12846,12868

    "march equinox in +09:00": {
      "name": {
        "en": "Spring Equinox Day",
        "jp": "春分の日"
      },
      "active": [
        {
          "from": "1948-07-20T00:00:00.000Z"
        }
      ]
    },
    "substitutes march equinox in +09:00 and if sunday then next monday": {
      "substitute": true,
      "name": {
        "en": "Spring Equinox Day",
        "jp": "春分の日"
      },
      "active": [
        {
          "from": "1973-04-12T00:00:00.000Z"
        }
      ]
    },

13100a13124,13146 }, "september equinox in +09:00": { "name": { "en": "Autumnal Equinox Day", "jp": "秋分の日" }, "active": [ { "from": "1948-07-20T00:00:00.000Z" } ] }, "substitutes september equinox in +09:00 and if sunday then next monday": { "substitute": true, "name": { "en": "Autumnal Equinox Day", "jp": "秋分の日" }, "active": [ { "from": "1973-04-12T00:00:00.000Z" } ] ` all this code is not cover by test and don't work.

aradnom commented 1 year ago

Had this same issue attempting to generate 2022 holidays for both Japan and Taiwan, but it appears to be date-dependent, was a problem on Dec. 7th but seems fine today, same version (3.14.2).

SSANSH commented 1 year ago

I try with 2022 and its doesnt work today on my side, something is broken with date-holidays-parser and then astronomia packages.

commenthol commented 1 year ago

Please find a sample project at https://github.com/commenthol/date-holidays-example which proves that the module is usable either as ESM or commonJS module. I suspect that the issue is related to your project setup. Please feel free to share a sample project which demonstrates your experienced issues.

commenthol commented 1 year ago

I now can confirm the issue. I oversaw that it only occurs with equinox dates. This was introduced by updating to rollup ^3 in date-holidays-parser. For the moment please add npm i date-holidays-parser@3.4.1 to your project, this will downgrade the parser. Will see how to provide a fix here.

SSANSH commented 1 year ago

Hi, Thanks for your sample project but my exemple was already a sample project, so I don't need this and I confirm this not come from my sampe project :) . moreover yes I have the same result as you (see thread number two), rules are all with equinox and I have the same suspect date-holidays-parser. So Yes I will downgrade the parser as you suggest, and then I will wait for a fix.

commenthol commented 1 year ago

Hi @SSANSH, date-holidays-parser@3.4.3 reverts back to rollup@2 Can you please give it a try with this downgraded version?

SSANSH commented 1 year ago

@commenthol I tried with npm i date-holidays-parser@3.4.1 and it doesnt work in fact. I have the same ussue, sorry for the previous bad answer.

commenthol commented 1 year ago

@SSANSH Can you please remove all node_modules and your lock file and do a install install? Do not forget to remove the date-holidays-parser@3.4.3 line in you package.json. That should work. I'll bump the versions with the next patch.