-
Notifications
You must be signed in to change notification settings - Fork 54
Using Twix.js with Moment timezone via Webpack #102
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
Comments
Have you tried this: import moment from 'moment';
import 'moment-timezone';
import 'twix';
moment.tz // => real thing
moment.twix // => real thing I haven't tried that in Webpack but I think it should work. |
Closing this because of its age. @ me and I'll reopen |
Hi, we've run into what I think the issue here is. For a larger project there will often be many versions of moment in the node_modules directory. We often get errors like: It would be helpful to have an I hope I explained that properly. |
That's a perfectly reasonable request, but how would it work, given that Twix already tries to do that on its own? I'm loath to break that for existing users. Perhaps it would get Moment on its own automatically and just additionally expose But before we go down that path: I had thought the whole point of using |
Yeah, that was what I was thinking. extend() would just extend the version passed. It would still automatically extend the moment it gets to not break existing apps. moment-timezone actually lists moment as a dependency so it may get it's own version. I did a I did a little more poking based on what I said in the previous paragraph and I think the workaround is don't require moment just moment-timezone so it loads it's own version of moment and then twix. Like this: var moment = require('moment-timezone');
require('twix'); That way twix is getting the moment that moment-timezone is loading. Best to do this as soon as possible in main.js (or which ever file is the app's entry point.) That way moment, moment-timezone and twix are all resolved by node early. |
You can probably close this since I think the above is the answer. Maybe add a note in the readme for people using twix and moment-timezone. |
I'm going to leave this open while I think about ways to make this cleaner. Also, it looks like the OP was trying to use the code you posted (or its ES6 equivalent) with no luck |
Thanks @baldmountain @icambron for take a look on this issue 👍 |
You could use the approach from https://github.com/jsmreese/moment-duration-format this works for me with moment-timezone, unfortunatly twix works not with moment-timezone. Could you just likewise export the init function? |
@DerGuteWolf Can you explain that more? |
Well, the problem is, with moment-timezone and npm you shouldn't do require('moment').
(factory corresponds to your makeTwix)
As asimple first step, you could also simply do this: |
That seems reasonable to me. Would take a pull request. |
Do you mean the way moment-duration does this or the simple first step? |
I think both moment-timezone and twix should not mutate the constructs provided by another package, in this case moment. Or, more generally, imports should not have any side-effects. There is no value in being able to do |
In a multi-plugin world `require 'moment'` leads to problems discussed in icambron#102
❗ This is not possible to use Twix.js with moment-timezone when I importing like this via Webpack
And use something like
So I got error
🎉 But this is possible to do if I want to use moment as moment-timezone
And use something like
Question is, Does it possible to use
moment.twix()
when moment is moment-timezone ?PS: All are latest versions
Thanks so much.
The text was updated successfully, but these errors were encountered: