vvo / tzdb

🕰 Simplified, grouped and always up to date list of time zones, with major cities
MIT License
772 stars 53 forks source link

Raw Time Zones import not being babel-ified correctly #257

Closed Jackman3005 closed 2 years ago

Jackman3005 commented 2 years ago

Hello,

I am trying to use your awesome library in my expo/react-native app (mobile and web). I am running into an issue when using getTimeZones on a mobile device, everything seems to work fine on web.

I've discovered that the _rawTimeZones variable in dist/getTimeZones.js is not being set correctly in the mobile environment and is resulting in an array with 0 timezones.

I found that if I change the require statement at the top from:

var _rawTimeZones = _interopRequireDefault(require("../raw-time-zones.json"));

to

var _rawTimeZones = require("../raw-time-zones.json");

(and remove the corresponding .default)

I am able to get this to work just fine on web and mobile.

I'm not sure if this points more towards a configuration issue on my side or on tzdb's, but generally I can use all other JS libraries out there without issues.

I'm not a babel expert, so I don't know exactly why it's transpiling the code to require default from a json file, but it appears strange to me that it's doing so.

Happy to help with a PR if someone can point me in the approved direction.

Cheers, Jack

P.S. using "@vvo/tzdb": "^6.50.0"

Jackman3005 commented 2 years ago

Although I don't know why this was happening (and only happening for this library) in my case. It magically disappeared when we upgraded Expo from v44 to v45...

I'm still having problems with this library because of its use of Intl and the poor support of Intl on mobile devices when using the hermes-engine JS environment. This is resulting in 0 timezones being returned since DTF creation fails for all of them. (separate issue)