Skip to content

Commit

Permalink
Merge pull request #4213 from ichernev:fix-react-native
Browse files Browse the repository at this point in the history
[critical] Rename dynamic require to avoid React Native crash
  • Loading branch information
ichernev committed Oct 10, 2017
2 parents 36f29b3 + 6a230ae commit 967ee9a
Showing 1 changed file with 6 additions and 3 deletions.
9 changes: 6 additions & 3 deletions src/lib/locale/locales.js
Expand Up @@ -46,19 +46,22 @@ function chooseLocale(names) {
}

function loadLocale(name) {
var oldLocale = null;
var oldLocale = null,
// workaround for React Native 0.49+
pretendingNotToRequire = require;

// TODO: Find a better way to register and load all the locales in Node
if (!locales[name] && (typeof module !== 'undefined') &&
module && module.exports) {
oldLocale = globalLocale._abbr;
try {
require('moment/locale/' + name);
pretendingNotToRequire('moment/locale/' + name);
} catch (e) {
// In the test environment, the external module 'moment'
// can't be resolved because we're running inside it.
// Fallback to using the old relative import
try {
require('./locale/' + name);
pretendingNotToRequire('./locale/' + name);
} catch (e) { }
}

Expand Down

1 comment on commit 967ee9a

@arondeparon
Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@ichernev Great to see this fix being merged, thanks! Any idea on when we can expect this in a npm-ready release?

Please sign in to comment.