Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Using moment-timezone-utils in TypeScript loads latest data #938

Open
shamsup opened this issue Apr 21, 2021 · 1 comment
Open

Using moment-timezone-utils in TypeScript loads latest data #938

shamsup opened this issue Apr 21, 2021 · 1 comment

Comments

@shamsup
Copy link

shamsup commented Apr 21, 2021

Moment-timezone version which you use:

Version: 0.5.33
TypeScript: 3.7.4

Note: many issues are resolved if you just upgrade to the latest version

Issue description:

Using moment-timezone-utils with typescript will load the data from the base moment-timezone import.

import moment from 'moment';
import 'moment-timezone/moment-timezone';
import 'moment-timezone/moment-timezone-utils';

console.log(moment.tz.dataVersion) // => '2021a'

I'd expect the dataVersion to be undefined with no data loaded.

Leaving out the moment-timezone-utils gives the expected empty string.

import moment from 'moment';
import 'moment-timezone/moment-timezone';

console.log(moment.tz.dataVersion) // => ''
@ichernev
Copy link
Contributor

The issue is that we load ./ for node, which is ./index.js which loads the data, by design.

Here's a patch that fixes it:

diff --git a/moment-timezone-utils.js b/moment-timezone-utils.js
index 73d088a..45b2991 100644
--- a/moment-timezone-utils.js
+++ b/moment-timezone-utils.js
@@ -9,7 +9,7 @@
 
        /*global define*/
     if (typeof module === 'object' && module.exports) {
-        module.exports = factory(require('./'));     // Node
+        module.exports = factory(require('./moment-timezone'));     // Node
     } else if (typeof define === 'function' && define.amd) {
                define(['moment'], factory);                 // AMD
        } else {

I have to wrap my head around all the exported items to make sure we don't break somebody's workflow...

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants