RequireJS - loading an already loaded module

I am trying to use RequireJS to load browser modules and I had an interesting problem.

I have 3 modules named a , b and c having this simple source code:

a.js

 define(['./b', './c'], function(c, b) { console.log('A IS LOADED!'); return 'A'; }); 

b.js

 define(function() { console.log('B IS LOADED!'); return 'B'; }); 

c.js

 define(function() { console.log('C IS LOADED!'); return 'C'; }); 

When I load module a by itself, everything works fine, the following code starts and returns "A":

 require(['./a'], function(a) { console.log(a); // 'A' }); 

But if I need two different modules, one of which is already loaded:

 require(['./a', './c'], function(a, c) { console.log(a, c); }); 

RequireJS will be mistaken:

 C IS LOADED! B IS LOADED! require.js load timeout for modules: ./c 

when it is already loaded.

Has anyone encountered this problem before? How can I solve it?

+7
source share
1 answer

According to RequireJS website ( http://requirejs.org/docs/errors.html#timeout ):

Possible causes and corrections:

  • A script error has occurred in one of the modules listed. If there is no script error in the console error browser, and if you are using Firebug, try loading the page in another browser, such as Chrome or Safari. Sometimes script errors do not appear in Firebug.

  • The path configuration for the module is incorrect. Check the "Network" or "Network" tab in the browser developer tools to see if there is 404 for the URL that will map to the module name. Make sure the script file is in the right place. In some cases, you may need to use the path configuration to fix the URL resolution for the script.

0
source

All Articles