Require.js Error: Load timeout for modules: backbone,jquerymobile

后端 未结 6 2156
名媛妹妹
名媛妹妹 2020-12-04 09:34

I am trying to use r.js to optimize my code but I keep running to this error:

Tracing dependencies for: init

Error: Load timeout for modules: backbon         


        
相关标签:
6条回答
  • 2020-12-04 09:37

    In case others have this issue and still struggling with it (like I was), this problem can also arise from circular dependencies, e.g. A depends on B, and B depends on A.

    The RequireJS docs don't mention that circular dependencies can cause the "Load timeout" error, but I've now observed it for two different circular dependencies.

    0 讨论(0)
  • 2020-12-04 09:48

    The Error

    I recently had a very similar issue with an angularJS project using requireJS.

    I'm using Chrome canary build (Version 34.0.1801.0 canary) but also had a stable version installed (Version 32.0.1700.77) showing the exact same issue when loading the app with Developer console open:

    Uncaught Error: Load timeout for modules
    

    The developer console is key here since I didn't get the error when the console wasn't open. I tried resetting all chrome settings, uninstalling any plugin, ... nothing helped so far.

    The Solution

    The big pointer was a Google group discussion (see resources below) about the waitSeconds config option. Setting that to 0 solved my issue. I wouldn't check this in since this just sets the timeout to infinite. But as a fix during development this is just fine. Example config:

    <script src="scripts/require.js"></script>
    <script>
      require.config({
        baseUrl: "/another/path",
        paths: {
          "some": "some/v1.0"
        },
        waitSeconds: 0
      });
      require( ["some/module", "my/module", "a.js", "b.js"],
        function(someModule,    myModule) {
          //This function will be called when all the dependencies
          //listed above are loaded. Note that this function could
          //be called before the page is loaded.
          //This callback is optional.
        }
      );
    </script>
    

    Most common other causes for this error are:

    • errors in modules
    • wrong paths in configuration (check paths and baseUrl option)
    • double entry in config

    More Resources

    Troubleshooting page from requireJS: http://requirejs.org/docs/errors.html#timeout point 2, 3 and 4 can be of interest.

    Similar SO question: Ripple - Uncaught Error: Load timeout for modules: app http://requirejs.org/docs/errors.html#timeout

    A related Google groups discussion: https://groups.google.com/forum/#!topic/requirejs/70HQXxNylYg

    0 讨论(0)
  • 2020-12-04 09:51

    The reason for the issue is that Require.js runs into the timeout since the project might have dependencies to large libraries. The default timeout is 7 seconds. Increasing the value for this config option (called waitSeconds) solves it of course but it is not the right approach. Correct approach would be to improve the page loading time. One of the best technics to speed up a page loading is minification - the process of compressing the code. There are some good tools for minification like r.js or webpack.

    0 讨论(0)
  • 2020-12-04 09:55

    Require.js has a Config option called waitSeconds. This may help.

    RequireJS waitSeconds

    Here's an example where waitSeconds is used:

    requirejs.config({
        baseUrl: "scripts",
        enforceDefine: true,
        urlArgs: "bust=" + (new Date()).getTime(),
        waitSeconds: 200,
        paths: {
            "jquery": "libs/jquery-1.8.3",
            "underscore": "libs/underscore",
            "backbone": "libs/backbone"
        },
        shim: {
            "underscore": {
                deps: [],
                exports: "_"
            },
            "backbone": {
                deps: ["jquery", "underscore"],
                exports: "Backbone"
            },
        }
    });
    
    define(["jquery", "underscore", "backbone"],
        function ($, _, Backbone) {
            console.log("Test output");
            console.log("$: " + typeof $);
            console.log("_: " + typeof _);
            console.log("Backbone: " + typeof Backbone);
        }
    );
    
    0 讨论(0)
  • 2020-12-04 10:02

    Default value for waitSeconds = 7 (7 seconds)

    If set to 0, timeout is completely disabled.

    src: http://requirejs.org/docs/api.html

    0 讨论(0)
  • 2020-12-04 10:02

    I only get this error when running tests on Mobile Safari 6.0.0 (iOS 6.1.4). waitSeconds: 0 has given me a successful build for now. I'll update if my build fails on this again

    0 讨论(0)
提交回复
热议问题