Error: Invalid unit value NaN in getTimeZones() method
Hello!
I have that error when I try it:
index.js
import { getTimeZones, rawTimeZones, timeZonesNames } from "@vvo/tzdb"; console.log(getTimeZones());
error
InvalidArgumentError: Invalid unit value NaN
at asNumber (C:\Users\lacer\Desktop\testando\node_modules\luxon\build\node\luxon.js:439:87)
at normalizeObject (C:\Users\lacer\Desktop\testando\node_modules\luxon\build\node\luxon.js:450:35)
at Function.fromObject (C:\Users\lacer\Desktop\testando\node_modules\luxon\build\node\luxon.js:2868:15)
at getOffsetString (C:\Users\lacer\Desktop\testando\node_modules@vvo\tzdb\dist\formatTimeZone.js:23:50)
at format (C:\Users\lacer\Desktop\testando\node_modules@vvo\tzdb\dist\formatTimeZone.js:18:44)
at C:\Users\lacer\Desktop\testando\node_modules@vvo\tzdb\dist\getTimeZones.js:29:54
at Array.map (
Am i doing something wrong?
Hi there, I just tried the latest version and it's working well, so there must be some difference in our environments here.
Can you tell me:
- what's the Node.js version you're using?
- are you trying to use the code with webpack or any other bundler?
- are you on Windows?
Thanks!
@vvo/tzdb: "^5.4.0" Node: v12.16.1 No bundlers Windows Home 10 version 1909
Probably is environment, I think so...
I tried to debug the code and I found the problem. In C:\Users\lacer\Desktop\testando\node_modules@vvo\tzdb\dist\getTimeZones.js, line 20, there is a method from luxon that gets currentDate for using in currentTimeOffsetInMinutes:
=================
const currentDate = _luxon.DateTime.fromObject({ locale: "en-US", zone: timeZone.name });
console.log(currentDate);
const timeZoneWithCurrentTimeData = { ...timeZone,
currentTimeOffsetInMinutes: currentDate.offset
};
When I log timeZone.name === "Antarctica/McMurdo", the date object returned from luxon shows that zone is not supported:
================= DateTime { ts: 1597603035971, _zone: LocalZone {}, loc: Locale { locale: 'pt-BR', numberingSystem: null, outputCalendar: null, intl: 'pt-BR', weekdaysCache: { format: {}, standalone: {} }, monthsCache: { format: {}, standalone: {} }, meridiemCache: null, eraCache: {}, specifiedLocale: null, fastNumbersCached: null }, invalid: Invalid { reason: 'unsupported zone', explanation: 'the zone "Antarctica/McMurdo" is not supported' }, weekData: null, c: null, o: null, isLuxonDateTime: true }
I removed the "Antarctica/McMurdo" from raw-time-zones.json and run correct!
The problem is my luxon version not recognized this zone. Maybe you need validate if currentDate returns a valid value to determine that loop should be execute, or run the next one.
Having the same issue, same stack trace.
tzdb 5.4.0, luxon 1.24.1 Safari 13.1 on iOS 13.6
I'm getting this from our client-side error reporting and unfortunately cannot reproduce even with the same Safari version, so cannot tell on which timezone it stumbles. But ignoring unsupported timezones seems like a good idea, as they may differ in different environments.
A reproducible example here on RunKit. Seems to work fine with Node v14, but not the latest LTS v12.
Ok got it, I believe Node v14 is the only version that added this timezone, let me fix this!
:tada: This issue has been resolved in version 5.4.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket:
Let me know if this is working for you now
Perfect! The new validation is running! Thanks guy!!!!!