Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

revert locale fallbacks in require, re-add react native aliasing #4232

Merged
merged 1 commit into from
Oct 11, 2017
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
19 changes: 5 additions & 14 deletions src/lib/locale/locales.js
Original file line number Diff line number Diff line change
Expand Up @@ -50,21 +50,12 @@ function loadLocale(name) {
// 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);
} 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);
} catch (e) { }
}

// because defineLocale currently also sets the global locale, we
// want to undo that for lazy loaded locales
getSetGlobalLocale(oldLocale);
oldLocale = globalLocale._abbr;
var aliasedRequire = require;

Choose a reason for hiding this comment

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

Why is it aliased?

Copy link
Member Author

Choose a reason for hiding this comment

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

TBH I don't know why this makes metro-bundler work for React native, I just know that it does do that.

Copy link

Choose a reason for hiding this comment

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

This is still not working for a lot people because some react native modules e.g. react-native-gifted-chat are referencing moment-with-locales.min.js i.e. the minified version. For some reason, the minified version does not seem to have the fix.

When I fixed the code in moment-with-locales.min.js using your approach of aliasing "require", 2.19.1 began to work for me.

aliasedRequire('./locale/' + name);
getSetGlobalLocale(oldLocale);
} catch (e) {}
}
return locales[name];
}
Expand Down