Skip to content

Commit

Permalink
Rename dynamic require to avoid React Native crash
Browse files Browse the repository at this point in the history
  • Loading branch information
ichernev committed Oct 9, 2017
1 parent 36f29b3 commit 6a230ae
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

0 comments on commit 6a230ae

Please sign in to comment.