From: Thomas Stephenson Date: Tue, 27 Jun 2017 12:36:07 +0000 (+1000) Subject: Fix #4031 - Missing ES6 module during tree shaking X-Git-Tag: 2.19.0~17^2 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8d2df8c37d76d54aaf325acc5ebe49ff24eff474;p=thirdparty%2Fmoment.git Fix #4031 - Missing ES6 module during tree shaking Cannot import the locale relatively, since the code exists in a different location in the bundled ES5 module than it does in ES6. In order to run tests locally (where the external 'moment' library can't be loaded), fall back to using the relative import. --- diff --git a/src/lib/locale/locales.js b/src/lib/locale/locales.js index 99ee11571..7df7ae3c4 100644 --- a/src/lib/locale/locales.js +++ b/src/lib/locale/locales.js @@ -50,13 +50,21 @@ 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 { - oldLocale = globalLocale._abbr; - require('./locale/' + name); - // because defineLocale currently also sets the global locale, we - // want to undo that for lazy loaded locales - getSetGlobalLocale(oldLocale); - } catch (e) { } + 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); } return locales[name]; }