-
Notifications
You must be signed in to change notification settings - Fork 11.9k
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.js with requireJS #2906
Comments
@adrianhurt is it possible to create a fiddle with this for debug purposes? |
Sure! First, I've adapted one of the examples to use RequireJS. It uses And then I've tried to change
Even setting I suppose I'm missing some stupid thing, but I can't find any example using RequireJS. Thanks! |
Looks like this is because of require. The chart factory doesn't apparently get passed the moment object returned from the factory. Since it can't find it, it defaults to One solution to this would be to build using webpack or browserify since then all the dependencies would be included. |
Thank you. I've noted you marked this issue as a bug, so I suppose it will be fixed. My project is now in development so meanwhile I'll use it with |
Same problem with angular-cli (SystemJS) and Angular 2. |
It appears Chart.bundle.js does not attach moment globally to the window object? |
I think it's exactly that |
with requireJS you would load moment.js like this
So inside that callback, the moment object is available but not globally (window.moment). And if you try to assign it to window.moment manually inside the callback, its too late because Chartjs has already been initialized by the time we get there. What is missing is way to pass the moment to Charts.js. For example
The actual moment "object" is not used until the time scale is initialized, yet chart.js wants it to be available at initialization time? |
Here is a workaround for requireJS which doesn't involve modifying chartjs. Create moment-fix.js which pre-loads moment.js and adds it to the global scope.
Setup a shim in your requireJS configuration to load moment-fix before chartjs.
|
Is this still causing an error or can this issue be closed? |
@zachpanz88 Pretty sure this issue still exists. The requirejs shim solution is alright, but making the factory pattern logic more robust still seems like the right permanent fix. |
Any progress on this issue? It still persists for me. |
This problem happens to me at src/scales/scale.time.js on line 7 Solution: Comment: Versions: |
I have the same issue of @chrisli30 with Ionic 3. |
I removed all usage of momentjs in favor of date-fns in my Angular 5 (+ angular-cli) app only to realize that Chartjs depends on Momentjs. |
This should've been fixed long time ago. Any progress? |
Hi, I'm trying to use chart.js and moment.js using requireJS, but I always get the following error:
I can use
Chart.bundle.js
and it works but I can't usemoment
from it, so I need to import it independently.I've tried to find any example on the web without success. And the docs says that:
But the examples in the repository import it twice...
Thanks
The text was updated successfully, but these errors were encountered: