El_Matella El_Matella - 2 months ago 19
Node.js Question

MomentJS doesn't load locales

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

Fka Fka
Answer

According to documentation please make sure that you have imported locale files or used minified file:

locale/*.js

or

min/moment-with-locales.js