I just updated form [email protected] to [email protected] in my Ember.js application and now I am getting an error the moment is not defined when I enter moment() into the console or include it in my scripts.
On the docs I saw "Since 2.4.0 the globally exported moment object is deprecated." which I think is the issue here but I am unsure how I can set moment globally in ember so that all of the references to moment() in our code base currently aren't broken.
I have tried updating the line where we were doing require('moment') to var moment = require('moment') but it has the same result. Even if I put a debugger directly after the var moment = ... line and then enter moment() into the console I still get that moment is undefined.
moment(undefined) is equivalent to moment() , which assumes the initial state to be the current date/time. moment(null) , on the other hand, is not a thing. It is not valid (at least not in the version I'm playing with), and has undocumented results.
Moment JS allows displaying of date as per localization and in human readable format. You can use MomentJS inside a browser using the script method. It is also available with Node. js and can be installed using npm.
MomentJs recently announced that the library is now deprecated. This is a big deal for the javascript community who actively downloads moment almost 15 million times a week. With that I began a journey during a Hackathon to replace moment in a core library at my company.
noun In mech., a zero moment.
You want the Browser section of the new Documentation.
So...
<script src="moment.js"></script>
<script>
moment().format();
</script>
Edit
Having said that, it looks like this will probably give you the same issue.
It looks like Moment.js is trying to encourage you to use a package manager in order not to dirty the namespace with global variables.
Go read up on CommonJS and AMD, and try and factor it in to your current stack.
You should be doing something like:
var moment = require('moment');
moment().format();
But in order to use require
you need a module system like the ones aforementioned.
But
The obvious fix is to rollback your version of Moment.js, so long as you don't need new functionality. How important can an update on a simple time/date library really be?
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With