-
Notifications
You must be signed in to change notification settings - Fork 838
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
Error while using moment #449
Comments
Hi I was having the same issue make sure you are using at least moment 2.6.0 as in the docs |
I am currently using latest version i.e. 2.17.1 and I am still getting the same error |
This issue seems to be fixed by settings
Might be issue with import. Can anyone fix? |
I'm also experiencing this issue using es6 imports. dep versions:
code:
Produces:
Not 💯 on whether or not I am importing |
Same issue here, I hope this get addressed any time soon 😞 |
I'm a little confused about what is happening here. It looks like y'all are having trouble using ES6 import syntax with webpack. What I don't understand is how you're importing moment as an ES6 module in the first place -- there's absolutely nothing in our packaging that would allow you to import moment using ES6 syntax and get anything other than the normal browser global. Something is rewriting our packaging in order to achieve this result -- presumably webpack, but I've never used it so I don't really know how it works. I'm inherently skeptical about adding code to moment-timezone to support a module system that moment and moment-timezone do not support. Many webpack users are experiencing pain with Moment's locales now, which is fundamentally rooted in the fact that we built our UMD packaging under the assumption that everyone using CommonJS is using Node (which was generally true at the time). So this time around, I really don't want to assume that everyone using ES6 is using webpack or other current-generation tools. In other words, I'd like to be convinced that this solution will always be the right thing to do to support ES6 modules, even in a future where another packaging tool decides to translate our UMD setup differently, or even in a future where Moment supports ES6 modules natively. Could someone please explain in more detail what webpack is doing here, and why #476 would be a reasonable solution to include in moment-timezone? |
For what it's worth, I'm starting a webpack project right now (like, on day 1 here). I'll pull in moment since I tend to always do so anyways and see what I can make of it. |
Essentially the issue we have is at present is if we do something like
or We get the exception trying to split moment.version which is undefined Importing moment works fine but without the timezone functionality such as
I trust that the best way is to properly support ES6 modules but #476 is very non-disruptive PR as moment.version would error if its undefined. |
Sorry, I guess I was unclear. I understood that moment-timezone is getting a wrapped copy of moment in your environment, and that you want it to be unwrapped so that the plugin works correctly. What I don't understand is why moment is getting wrapped in your environment, nor do I know if there is good reason to expect this wrapping behavior to be consistent with other environments (including future tools) that implement the same goals. Without that information, I don't personally feel confident that #476 will continue to be non-disruptive as the Javascript ecosystem continues to evolve over time. Put another way, I'm not sure whether this would be properly fixed in moment-timezone or in webpack. Absent other information, I think it sounds suspiciously like webpack might be breaking moment's perfectly-valid AMD modules in the process of translating them to ES6 modules. If that is actually what is happening, then I would prefer to have webpack fix this instead of moment. But if that's not what is going on, or if we should expect the same behavior if/when we decide to natively support ES6 modules ourselves, then we should carefully vet and move forward with a solution in moment. (And then we should share that solution with other projects that also use UMD, since they will presumably face similar issues.) tl;dr -- Yes, I want to get your build working -- but I want to make sure we do that in a way that avoids similar issues in the future, in moment and ideally also in other libraries that use the same packaging structure. I hope we'll take the time required to sort out exactly what is going on, in order to accomplish that larger goal. |
Seeing this problem as well. Using the following: |
It looks like this is happening because of a breaking change made in the babel6 transpiler (almost always required in webpack). Here's the issue on babel's GitHub. Here's a related Stack Overflow link. Here is a babel plugin that may help. |
same here Please if anyone have workaround please post |
The link above to https://github.com/59naga/babel-plugin-add-module-exports plus the following worked for me. import moment from 'moment';
import 'moment-timezone'; |
Same. in fact, this works for me as well: import moment from 'moment-timezone'; |
If using in browser you have to use the moment.js file as well.... The moments homepage where you can download moment-timezone.js and moment-timezone-with-data.js does not make it clear you also need moment.js............ `<script type="text/javascript" src="../js/moment.min.js"></script> `<script> console.log(a.format()); moment.js is available here: https://cdnjs.com/libraries/moment.js Info found here: https://momentjs.com/docs/ |
This hack still doesn't work for me, any other suggestion? |
This doesn't work for me either? Anyone figures it out yet? |
#476 this one seems to work like @BipinBhandari suggested. |
Same issue 2.19.0 |
Latest version also seems to break for us using Webpack. Everything was fine earlier. |
I have same problem, in my case it resolve by using |
@Etrimus have you fix by using moment 2.18.1? |
@dharmesh03 Yes, I fixed it just now in my project (Angular 4, Webpack). In My case |
Was this breaking change released today? Was working fine last night, redeployed today and got this error. Spent hours debugging it |
Nothing of the above works for parcel + typescript. |
Is there anyway I can get this fixed and use on a |
Is there a way I can get timezone list with luxon ? |
Nope, the purpose of Luxon is that it only supports browsers that have the timezone list. You can polyfill that if you'd like. |
For me the issue was caused by moment being mocked in the wrong way in a test. |
This is definitely a bad export compatibility that can be fixed with ease. I find a workaround doing simply this: echo 'export default moment;' >> node_modules/moment-timezone/index.js; Is it enough? 🤔 |
react-boilerplate/react-boilerplate#1569 (comment) This solution worked for me for react-boilerplate. |
I'm having this issue as well. |
In Angular 9, adding this to {
"compilerOptions": {
"paths": {
"moment": ["node_modules/moment/min/moment.min.js"]
}
}
} Then import
There is a console warning which isn't ideal (see this) but I haven't seen any side-effects yet.
|
still an issue.
(Remove package-lock and node_modules to be sure) |
Legit, this fixed it right away for me. Thanks for saving me hours! |
This fixed my issue, working with Yarn, seems that adding "resolutions" is necessary. |
After about a billion Google searches, trying to solve this, I stumbled on the following. Like many others on this thread, I tried all of the above and nothing resolved the problem. To summarize: Here's what I tried first - but made no difference (Still had package.json (NOTE: no moment):
*.component.ts
ts.config.json
Here's what fixed it: I noticed that my tsconfig.json was still trying to compile for es2015. When I changed it to the following, all of a sudden my project came back to life:
Curiously, when I set it back to If somebody who knows more about Angular/Typescript than me can figure out the effect of what I did and explain it properly to others, that would be great. |
Same issue here. Changing require('moment') by require('moment').default in moment-timezone.js works |
ionic angular taken down also not fun |
there is an open PR since 3 years now (#476) - i dont think maintainers will fix this any time soon |
this is moment this is luxon npm i luxon this is how i got around it moment sounds like it was designed terribly and on its way out |
@butterflyhug Moment gets wrapped in a property called 'default' because that's how the default exports from ES6 modules are designed to achieve backwards-compatible interop when using the commonjs module system as an output target: |
Hi, don`t know who to blame, the timezone or cypress guys, currently I am using Angular 6.x, typescript 2.9.x, cypress and its related libs as mentioned in the repo above. |
Downgrading and locking dependency versions fixed it for me:
|
Thanks, it seems they have release buggy 2.25 today some hours before, reverted to 2.24.0 and 0.5.21 , its working |
After debugging this for several hours, I've installed |
I still have problems with |
Works fine for me after an update: moment: 2.29.1 Imported like that: import * as moment from 'moment-timezone'; Gives you the possibility to use the timezone as well: const date = moment.tz(ride.date, 'UTC').tz('Europe/Paris'); I am not pretty sure this is the way to go, but it works. |
I'm having this error with moment while importing the react-moment library. |
Looks like this issue was fixed by #476, released in Moment Timezone I've also added some ES6 examples to the Node.js section of the docs. |
I am getting the following error while trying to use this library in my project
The text was updated successfully, but these errors were encountered: