Reputation: 16344
I am building something with moment and nodejs, but for some reason, the locales don't get loaded. Here is some code:
import moment from 'moment'
moment.locale('fr');
console.log(moment.locales());
So the console.log only returns the en
locale so I suppose that the other locales aren't loaded.
However, the documentation says:
If there is a locale file in moment-root/locale/ named after that key, the first call to moment.locale will load it.
When I check in my node_modules/moment/locale
, I have indeed a fr.js
file.
So what am I doing wrong? Am I missing something to load my locales?
Thanks a lot for your help!
EDIT: I am using version ^2.14.1
of momentjs
Upvotes: 2
Views: 3436
Reputation: 6234
According to documentation please make sure that you have imported locale files or used minified file:
locale/*.js
or
min/moment-with-locales.js
Upvotes: 2
Reputation: 16344
I found the solution, I needed to import the locale into my main js file:
import 'moment/locale/fr';
Upvotes: 5