`

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

阅读更多
Ten. Million. Questions. Let's celebrate all we've done together.
Take the 2-minute tour ×
Stack Overflow is a question and answer site for professional and enthusiast programmers. It's 100% free.

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: backbone,jquerymobile

The command I am running is this:

$ java -classpath /Users/dixond/build-tools/rhino1_7R4/js.jar:/Users/dixond/build-tools/closurecompiler/compiler.jar org.mozilla.javascript.tools.shell.Main /Users/dixond/build-tools/r.js/dist/r.js -o /Users/dixond/Sites/omm_mobile/js/build.js

My build.js file looks like this:

( {
    //appDir: "some/path/",
    baseUrl : ".",
    mainConfigFile : 'init.js',
    paths : {
        jquery : 'libs/jquery-1.8.3.min',
        backbone : 'libs/backbone.0.9.9',
        underscore : 'libs/underscore-1.4.3',
        json2 : 'libs/json2',
        jquerymobile : 'libs/jquery.mobile-1.2.0.min'
    },
    packages : [],
    shim : {
        jquery : {
            exports : 'jQuery'
        },
        jquerymobile : {
            deps : ['jquery'],
            exports : 'jQuery.mobile'
        },
        underscore : {
            exports : '_'
        },
        backbone : {
            deps : ['jquerymobile', 'jquery', 'underscore'],
            exports : 'Backbone'
        }
    },
    keepBuildDir : true,
    locale : "en-us",
    optimize : "closure",
    skipDirOptimize : false,
    generateSourceMaps : false,
    normalizeDirDefines : "skip",
    uglify : {
        toplevel : true,
        ascii_only : true,
        beautify : true,
        max_line_length : 1000,
        defines : {
            DEBUG : ['name', 'false']
        },


        no_mangle : true
    },
    uglify2 : {},
    closure : {
        CompilerOptions : {},
        CompilationLevel : 'SIMPLE_OPTIMIZATIONS',
        loggingLevel : 'WARNING'
    },
    cssImportIgnore : null,
    inlineText : true,
    useStrict : false,
    pragmas : {
        fooExclude : true
    },
    pragmasOnSave : {
        //Just an example
        excludeCoffeeScript : true
    },
    has : {
        'function-bind' : true,
        'string-trim' : false
    },
    hasOnSave : {
        'function-bind' : true,
        'string-trim' : false
    },
    //namespace: 'foo',
    skipPragmas : false,
    skipModuleInsertion : false,
    optimizeAllPluginResources : false,
    findNestedDependencies : false,
    removeCombined : false,
    name : "init",
    out : "main-built.js",
    wrap : {
        start : "(function() {",
        end : "}());"
    },
    preserveLicenseComments : true,
    logLevel : 0,
    cjsTranslate : true,
    useSourceUrl : true
})

And my init.js looks like this:

 requirejs.config({
      //libraries
      paths: {
          jquery:       'libs/jquery-1.8.3.min',
          backbone:     'libs/backbone.0.9.9',
          underscore:   'libs/underscore-1.4.3',
          json2 :       'libs/json2',
          jquerymobile: 'libs/jquery.mobile-1.2.0.min'
      },

      //shimming enables loading non-AMD modules
      //define dependencies and an export object
      shim: {
          jquerymobile: {
              deps: ['jquery'],
              exports: 'jQuery.mobile'
          },
          underscore: {
              exports: '_'
          },
          backbone: {
              deps: ['jquerymobile', 'jquery', 'underscore', 'json2'],
              exports: 'Backbone'
          }
      }
    });


requirejs(["backbone",], function(Backbone) {
    //Execute code here
});

What am I doing wrong in this build process?

shareimprove this question
 
    
I have the same problem , but only happens in chrome , in your case too ? –  Lucas Roselli Jul 15 at 13:52

6 Answers

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);
    }
);
shareimprove this answer
 
1  
Thanks! I was having the same problem but I didn't think that it was actually a timeout issue. It must be due to the size or complexity of jQuery because the error only occurs when a dependency is declared on jQuery. Changing waitSeconds to something larger allowed the build to complete successfully. –  Peter RebholzJan 14 '13 at 14:47
1  
I can confirm this. We have a bigger project with several dependencies to large libraries. With requireJS 2.0.6, that was fine. requireJS 2.1.4 however runs into the timeout. A higher value for waitSeconds solved it. –  phammer Jan 25 '13 at 11:07
    
Just opened a pull request to update the build.js example of require.js so that people become faster aware of the parameter. See github.com/jrburke/r.js/pull/362 –  phammer Jan 25 '13 at 11:36
3  
Thanks! This helped me. I wonder, are most folks using a non-default value for this property? Is 200 pretty common? What about 0? –  Josh Schultz Feb 12 '13 at 17:00 
2  
I also get a timeout in iOS/Safari (and not iOS/Chrome!) when loading the first time after cache is cleared. Backbone views fail to load with timeout. Setting waitSeconds really high does not help. My require() call includes 8 modules, each of which include 2 - 3 of their own modules (some being text! templates). If I reduce the 8 modules to 5, things load fine under iOS/Safari. I've checked the file paths as well as for syntax errors a dozen times. –  Chad Johnson Apr 29 '13 at 17:55 

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

shareimprove this answer
 

The default value for waitSeconds = 7 (7 Seconds)

If set to 0, timeout is completely disabled.

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

shareimprove this answer
 

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.

shareimprove this answer
 
2  
How did you go about identifying circular issues? Did you have to go through each defined module? – Paul Redmond Sep 30 '14 at 22:34
    
My issue came up when I added and changed some modules, so I was able to go through those changes, track down which added dependencies created the circular dependency loop, and remove them. –  Aaron Oct 3 '14 at 20:02
1  
xrayquire (a tool by requirejs) can check for circular dependencies –  Druska Jan 28 at 14:51
    
observed when loading a module A inside a callback function from another module B which required module A –  Jochen Bedersdorfer May 28 at 7:27

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

shareimprove this answer
 
    
thats 2 in a row! –  Adam Spence Aug 15 '14 at 11:09

check you have done something like this

require(["Q", "jquery"], function (Q, $) {

this should be

require(["q", "jquery"], function (Q, $) {

because we have to load all q js with that name as it's since all module load by q do not enter any reference other than "q" (or name that your q js file.)

shareimprove this answer
 

参考:http://stackoverflow.com/questions/14279962/require-js-error-load-timeout-for-modules-backbone-jquerymobile

分享到:
评论

相关推荐

    EurekaLog_7.5.0.0_Enterprise

    2)....Fixed: Range check error in processes information for x64 machines (affects startup of any EurekaLog-enabled module) 3)....Fixed: Auto-detect personality by project extension if --el_mode switch...

    require.js.rar

    《require.js——JavaScript模块加载与AMD规范解析》 在JavaScript的世界里,随着代码量的增加,管理和组织变得越来越复杂。require.js的出现,为解决这一问题提供了强大的解决方案。require.js是一个小巧但功能...

    DWR同一个页面中多次引用engine.js出现:Incomplete reply from server

    至于文件`jquery-require-sample`,这个名字表明可能是一个使用jQuery和RequireJS的示例项目。RequireJS是一个JavaScript模块加载器,它可以帮助组织和管理JavaScript文件的依赖关系。如果`engine.js`的加载问题与...

    Error:in ./node-modules/axios/lib/platform/index.js

    在JavaScript的开发环境中,我们经常会遇到各种错误,其中之一就是“Error in ./node_modules/axios/lib/platform/index.js”。这个错误提示通常意味着在项目中使用axios库时遇到了问题。Axios是一款非常流行的基于...

    require+r.js打包

    Require.js是一个流行的AMD(Asynchronous Module Definition)模块加载器,它允许我们在浏览器环境中按需加载JavaScript模块。而r.js是Require.js的一个配套工具,专门用于构建和优化项目,包括合并、打包和压缩JS...

    Node.js-基于require.js的Node打包方案

    在Node.js环境中,`require.js`通常用于浏览器端的模块加载和管理,它遵循AMD(Asynchronous Module Definition)规范,而Node.js自身则使用CommonJS规范处理模块导入。不过,有时候开发者可能希望将使用了require....

    一个结合了require.js+backbone的例子,适合初学者

    在IT行业中,JavaScript框架和技术栈的发展日新月异,Require.js和Backbone.js是其中两个重要的组成部分。Require.js是一款优秀的模块化加载库,它引入了AMD(Asynchronous Module Definition)模式,解决了...

    require.js插件-text.js使用

    在JavaScript的世界里,模块化开发变得越来越重要,RequireJS作为一款强大的异步模块定义(AMD)框架,极大地促进了这一进程。RequireJS不仅提供了一个管理依赖关系的机制,还支持加载各种资源,包括JavaScript、CSS...

    Javascript模块化编程(Require.js)

    Require.js是JavaScript的一个模块加载器,它引入了AMD(Asynchronous Module Definition)规范,为JavaScript提供了异步加载模块的能力,尤其适合在浏览器环境中处理大量依赖关系。 在JavaScript中,早期的编程...

    require.js的用法详解

    require.js是一种JavaScript模块加载器,设计用于解决JavaScript代码的组织和异步加载问题。在早期的网页开发中,所有的JavaScript代码通常被编写在一个文件里,随着项目规模的扩大,代码量增加,这种方法不再适用。...

    node.js报错:Cannot find module ‘ejs’的解决办法

    发现问题 最近同事问了一个问题,他在用node.js... at Function.Module._load (module.js:276:25) at Module.require (module.js:353:17) at require (internal/module.js:12:17) at new View (d:\WebClient\webstor

    require.js最新版2.3.5

    RequireJS不仅提供了模块化管理和异步加载,还支持插件系统,可以通过插件扩展其功能,如优化(r.js)、数据绑定(require-bind-dom)、CSS加载等。这些特性使RequireJS成为构建复杂前端应用的强大工具。 总之,...

    redis安装集群用redis-3.0.0.gem

    执行gem install redis /usr/local/lib/ruby/2.3.0/rubygems/core_ext/kernel_require.rb:55:in `require': cannot load such file -- redis (LoadError) from /usr/local/lib/ruby/2.3.0/rubygems/core_ext/...

    require.Sandbox:require.js 的沙箱模块

    require.js 的沙箱模块 require.Sandbox 是一个沙盒模块,集成到,可用于安全加载模块。 这个想法是将它们包装到一个沙箱中,以确保错误不会使整个应用程序崩溃,但可以以编程方式处理。 沙盒错误 修补错误函数 ...

    Javascript模块化编程(三)require.js的

    本篇将深入探讨require.js,一个广泛使用的JavaScript模块加载器和异步依赖管理库,尤其适用于大型项目的开发。 require.js的核心概念是AMD(Asynchronous Module Definition),即异步模块定义。它允许我们在脚本...

    require.js build

    `require.js` 是一个流行的JavaScript模块化加载器,它使得在浏览器端管理JavaScript代码变得更加有序和高效。在HTML5 Boilerplate(一个前端开发基础模板)中整合`require.js`,可以提升项目的构建质量和性能,特别...

    require.jquerytest

    在这个场景中,`require.jquerytest` 提到了如何使用`require.js`来加载jQuery库,这是Web开发中广泛使用的JavaScript库,提供了丰富的DOM操作、事件处理、动画效果以及Ajax功能。 首先,我们需要了解`require.js`...

    javascript高级模块化require.js的具体使用方法

    Require.js是一种JavaScript模块加载器,它遵循AMD(异步模块定义)规范,这种规范允许你以异步的方式加载JavaScript模块。它非常小巧,压缩后的大小只有14KB,适合用于管理前端JavaScript模块的加载,能够有效地...

    require.js

    * dist.js file to inject other files to completely enable this file. It is * the shell of the r.js file. */ /*jslint evil: true, nomen: true, sloppy: true */ /*global readFile: true, process: ...

    前端require.js

    **require.js**是一种在前端开发中广泛使用的JavaScript模块化加载框架,主要解决的是JavaScript在浏览器环境中缺乏内置模块化支持的问题。它引入了CommonJS风格的模块化机制,使得JavaScript代码可以像服务器端语言...

Global site tag (gtag.js) - Google Analytics