title: Moment Js loads localization too late when lazy loaded
body: <p>So I tried two ways to set the locale of Moment.js. Both ways won't work, or I should say it's just too late. My "wish" is to import the locale files asynchronous (inspired <a href="https://medium.com/@michalozogan/how-to-split-moment-js-locales-to-chunks-with-webpack-de9e25caccea" rel="nofollow noreferrer">here</a>).</p>
  
  <p>When I get to my page, the date is still in English formatted, even though it should be for example in German.</p>
  
  <p>I'm loading the data asynchronously with:</p>
  
  <pre><code>window.moment = require('moment');
  moment().format();
  
  window.moment = require('moment-shortformat');
  moment().short()
  
  window.moment = require('moment-timezone');
  
  const lang = document.documentElement.lang.substr(0, 2); //for the language
  
  if(lang != 'en'){
      import(`moment/locale/${lang}.js`);
      moment.locale(lang)
  }
  </code></pre>
  
  <p>Since <code>import(moment/locale/${lang}.js);</code> resolves a promise, I checked in console when the file is loaded. It's about 1 sec after the line <code>moment.locale(lang)</code> (no wonder moment is not ready to display the correct translated date).</p>
  
  <p>A small sanity check shows: the locale is correctly set when I write <code>moment.locale()</code> in the console.</p>
  
  <p>If I don't use lazy loading, like so:</p>
  
  <pre><code>import 'moment/locale/de';
  moment.locale(lang);
  </code></pre>
  
  <p>Everything works fine. </p>
  
  <p>My second approach is a bit longer but still had no luck. To sum it up. I created a javascript file on the backend with php with: </p>
  
  <pre><code>...
  $file = base_path('node_modules/moment/locale/' . $locale . '.js');
  ...
  </code></pre>
  
  <p>so I can call dynamically the right js file. But still no luck. </p>
  
  <p>Any idea what I'm doing wrong?</p>