]> git.ipfire.org Git - thirdparty/moment.git/commitdiff
[bugfix] Use __dirname for locale import if available
authorVentsislav Dimitrov <4097884+vdmtrv@users.noreply.github.com>
Fri, 25 Oct 2019 17:29:17 +0000 (18:29 +0100)
committerIskren Chernev <iskren.chernev@gmail.com>
Fri, 24 Apr 2020 18:09:29 +0000 (21:09 +0300)
React native doesn't like relative require calls. So use __dirname and
replace relative requires with absolute ones. Fall back to relative
require if __dirname is not present (for whatever reason).

Fixes #5252 and #5214

src/lib/locale/locales.js

index 86b933d66e8b97c5659b1681e5037f45ceb6c00a..7de3ec572926c0ebfaa47ccc3f49d23d5840ec86 100644 (file)
@@ -52,7 +52,7 @@ function loadLocale(name) {
         try {
             oldLocale = globalLocale._abbr;
             var aliasedRequire = require;
-            aliasedRequire('./locale/' + name);
+            aliasedRequire((typeof __dirname !== undefined ? __dirname : '.') + '/locale/' + name);
             getSetGlobalLocale(oldLocale);
         } catch (e) {
             // mark as not found to avoid repeating expensive file require call causing high CPU