Search code examples
javascriptgoogle-chromerequirejsamd

Chrome 49 timing and loading errors using require.js modules


My web app (which has lots of JS) has been working fine until this Chrome 49 update. (I know it's the update because it was working, then I updated my browser, and now its not).

There seems to be a timing issue on when the require.js define() functions are called. Although the require.js files are loaded first, my non-amd JS loaded after are firing first and causing issues like:

Uncaught Error: Module name [name] has not been loaded...

Is anyone else having this problem?


Solution

  • Not sure why this is the case, but my app entry point which begins to use all my loaded JS was wrapped with:

    $(function() {
    
      //...Start app
    
    })
    

    And I changed it to:

    require([], function(){
    
      //...Start app
    
    })
    

    I first tried window.addEventListener('DOMContentLoaded', function(){ but that didn't work any better. But wrapping with require() did. Hopefully this helps someone.