开发者

RequireJS - Loading an already loaded module

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

I have 3 modules named a, b and c having these 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 is working just fine, the following code runs and returns 'A':

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

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

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

RequireJS will error:

C IS LOADED!
B IS LOADED!
require.js load timeout for modules:开发者_如何学C ./c 

when it's obviously already loaded.

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


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

Likely causes and fixes:

  • There was a script error in one of the listed modules. If there is no script error in the browser's error console, and if you are using Firebug, try loading the page in another browser like Chrome or Safari. Sometimes script errors do not show up in Firebug.

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜