react-datepicker: Locale error when using date-fns
I’m trying to load es locale from date-fns and it throws an error, maybe this is related to date-fns itself.
It also happens with locales that are different than ‘en-GB’
Expected behavior
Load different locale than en-GB
Actual behavior
It crashes with this message:
RangeError: locale must contain localize property at format (modules.js?hash=6c38037b3206d378e63fb830a74ef56e49e3a6a4:8675) at formatDate (modules.js?hash=6c38037b3206d378e63fb830a74ef56e49e3a6a4:12089) at safeDateFormat (modules.js?hash=6c38037b3206d378e63fb830a74ef56e49e3a6a4:12
Steps to reproduce
import es locale and load it to DatePicker component
Can anyone try it out ? Thanks in advance
About this issue
- Original URL
- State: closed
- Created 6 years ago
- Comments: 16 (1 by maintainers)
Which version of date-fns are you using? To take advantage of the latest date-fns localization file features (and to better match the previous moment localization), the alpha version was used in react-datepicker, so you may need to try a new version of date-fns:
npm install date-fns@nextAnother option if you don’t want to go alpha is just grab the latest date localization files and use those independently: https://github.com/date-fns/date-fns/tree/master/src/locale
Alpha version. Brilliant…
@1S3L to install a specific version of date-fns you can use
npm install date-fns@2.0.0-alpha.27 --savefor example, but as @Darrken said, is preferable to only grab the files you need from that version.I don’t think switching to alpha version of that package is a good enough solution to justify closing this issue. I bet I’m not alone in not wanting to use unstable software on production.
How could you change from lowercase to the first letter to upper case and the rest to lowercase?