question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

[Packager] Requiring momentjs locale fails

See original GitHub issue

I’m trying to use a different locale for Moment.js, and I keep receiving the same error. This is the code:

var moment = moment();
moment.locale('es');

And I’m receiving this error in the Chrome Dev Tools console:

Error: Requiring unknown module "./locale/es". If you are sure the module is there, try restarting the packager.
 stack: 
  Object.ErrorUtils.applyWithGuard  index.ios.bundle:880
  require                           index.ios.bundle:195
  loadLocale                        index.ios.bundle:42796
  chooseLocale                      index.ios.bundle:42774
  locale_locales__getLocale         index.ios.bundle:42867
  Moment.locale                     index.ios.bundle:44506
  eval                              eval at evaluate …:1
 URL: undefined
 line: undefined

It doesn’t seems a Moment.js error though.

Issue Analytics

  • State:closed
  • Created 8 years ago
  • Comments:10 (3 by maintainers)

github_iconTop GitHub Comments

43reactions
brentvatnecommented, Jun 15, 2015

@alvaromb - just a quick thought from browsing the moment docs, what about:

var moment = require('moment');
var esLocale = require('moment/locale/es');
moment.locale('es', esLocale);
9reactions
ranyefetcommented, Dec 8, 2015

@brentvatne loading the locale directly i.e require('moment/locale/es'); works. I’m trying to set the locale dynamically, AKA, I get the locale from user device and then load the specific locale.

const deviceLocale = React.NativeModules.RNI18n.locale;
// fails
require('moment/locale/' + deviceLocale); 

Is there other way to solve it besides:

switch deviceLocale:
case 'es':
  require('moment/locale/es');
case 'he':
  require('moment/locale/he');
Read more comments on GitHub >

github_iconTop Results From Across the Web

How to prevent moment.js from loading locales with webpack?
I'm looking at the source and it seems that if hasModule is defined, which it is for webpack, then it always tries to...
Read more >
Moment.js documentation - DevDocs
Moment.js 2.29.4 API documentation with instant search, offline support, keyboard shortcuts, mobile version, and more.
Read more >
Moment.js | Home
Download · Install · Format Dates · Relative Time · Calendar Time · Multiple Locale Support.
Read more >
moment | Yarn - Package Manager
A JavaScript date library for parsing, validating, manipulating, and formatting dates. Project Status. Moment.js is a legacy project, now in maintenance mode.
Read more >
Module not found: Can't resolve 'moment' error | bobbyhadz
To solve the error "Module not found: Error: Can't resolve 'moment'", make sure to install the moment package by opening your terminal in...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found