RequireJS 和文本插件模块加载超时

发布于 2024-12-22 07:56:51 字数 343 浏览 0 评论 0原文

我在使用 RequireJS 文本插件时遇到一些问题。这可能是一个与路径相关的问题(或类似的明显问题),但我无法解决它,因为 chrome 控制台(打开 xhr)和 firebug 都没有给我任何信息,除了

Uncaught Error: Load timeout for modules: text 
http://requirejs.org/docs/errors.html#timeout

我很确定路径没问题,但是我找不到任何其他解释。有人知道如何调试这个吗?

我在服务器端使用node.js 和express,在客户端使用backbone 和jQuery。所有这些都可以通过 RequireJS 正确加载。

I am having some problems getting the RequireJS text plugin to work. This is possibly a path related issue (or something similarly obvious) but I can't solve it because neither the chrome console (with xhr turned on) nor firebug is giving me any info other than

Uncaught Error: Load timeout for modules: text 
http://requirejs.org/docs/errors.html#timeout

I am quite sure that the paths are OK but I cant find any other explanation. Does somebody have an idea how to debug this?

I am using node.js and express on the server side and backbone and jQuery on the client end. All of these get loaded correctly with RequireJS.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(5

记忆で 2024-12-29 07:56:51

我猜这是一个路径问题。我有相同的设置(节点/快递和主干),它似乎对我有用。这是我的 main.js 文件:

require.config({
  paths: {
    jquery: 'libs/jquery-1.7.1.min',
    underscore: 'libs/underscore',
    backbone: 'libs/backbone',
    text: 'libs/text',
    templates: '../views',
    persist: 'libs/persist/persist'
  }
});
require([
  'app'
], function(App){
  App.initialize();
});

这是我从模块内调用插件的方法:

define([
  'jquery',
  'underscore',
  'backbone',
  'collections/sub_elements',
  'collections/elements',
  'views/element',
  'text!../../../views/partials/_elements.html'
], function($, _, Backbone, sub_elementsCollection, collection, view,     template){

  var elementsView = Backbone.View.extend({
    // ... //
  });

  return elementsView;
});

I'm guessing it's a path issue. I have the same setup (node/express and backbone) and it seems to be working for me. Here is my main.js file:

require.config({
  paths: {
    jquery: 'libs/jquery-1.7.1.min',
    underscore: 'libs/underscore',
    backbone: 'libs/backbone',
    text: 'libs/text',
    templates: '../views',
    persist: 'libs/persist/persist'
  }
});
require([
  'app'
], function(App){
  App.initialize();
});

and here is how I call the plugin from within a module:

define([
  'jquery',
  'underscore',
  'backbone',
  'collections/sub_elements',
  'collections/elements',
  'views/element',
  'text!../../../views/partials/_elements.html'
], function($, _, Backbone, sub_elementsCollection, collection, view,     template){

  var elementsView = Backbone.View.extend({
    // ... //
  });

  return elementsView;
});
悲喜皆因你 2024-12-29 07:56:51

由于它在 Windows Phone 上,请尝试将“waitSeconds”设置为更大的数字。

移动速度很慢,但 require.js 默认会在 7 秒后超时,这对于移动体验/或互联网访问速度慢的用户来说通常太低了。

文档: http://requirejs.org/docs/api.html#config-waitSeconds

As it's on your windows phone, try to set "waitSeconds" to a higher number.

Mobile are slow, but require.js will timeout after 7 seconds by default, which is often way to low for mobile experience / or user with slow internet access.

doc: http://requirejs.org/docs/api.html#config-waitSeconds

对你而言 2024-12-29 07:56:51

我原来的答案

我在这里回答了一个类似的问题指向官方require.js 故障排除页面

就我而言,仅当在单个 MacBook 上的多个 Chrome 版本的 Chrome 上打开开发者控制台时,才会出现此错误。其他设备没有出现这个问题。因此,我可以通过更改那台计算机上的配置来确定。

waitSeconds

waitSeconds 选项 可以配置为无限 (0) 或您指定的任何值想要(以秒为单位)。默认值为 7 秒。示例配置:

<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> 

由于无限 (0) 禁用超时,我不建议在生产代码中使用此选项!如果您在任何地方运行代码时遇到此问题或禁用超时没有帮助,请继续阅读。

导致此问题的 3 个常见原因

  • 模块中出现错误 您在配置中加载了
  • 错误的路径(检查 pathsbaseUrl 选项)
  • 配置中的双重输入

有关此主题的更多信息检查顶部链接的原始答案。

My original answer

I answered a similar question here pointing to the official require.js troubleshooting pages.

In my case this error only occurred when the developer console was open on chrome for several chrome versions on a single macbook. Other devices didn't show the problem. Because of this I was OK by changing the config on that single computer.

waitSeconds

The waitSeconds option can be configured as infinite (0) or any value you want (in seconds). The default value is 7 seconds. An 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> 

Since infinite (0) disables the timeout I would not recommend this option for production code! If you encounter this problem running your code anywhere or disabling the timeout doesn't help then keep on reading.

3 common causes for this issue

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

For more on this topic check the original answer linked on top.

酷到爆炸 2024-12-29 07:56:51

我在错误地使用语法糖时收到此错误。
您不能既定义依赖项又使用 require 工厂函数。

//THIS WILL FAIL
define(['require'], function (require) {
    var namedModule = require('name');
});

来自文档

这会失败,因为 requirejs 需要确保加载并执行所有
调用上面的工厂函数之前的依赖关系。如果一个
依赖数组被赋予define(),然后requirejs假设所有
依赖项列在该数组中,并且它不会扫描
其他依赖项的工厂函数。所以,要么不传入
依赖数组,或者如果使用依赖数组,则列出所有
其中的依赖项。

因此,如果您指定依赖项数组,则不能同时依赖糖语法来工作。我认为这并不理想,但这就是 requirejs 的创建方式。

I got this error when incorrectly using the syntax sugar.
You can't both define dependencies and use the require factory function.

//THIS WILL FAIL
define(['require'], function (require) {
    var namedModule = require('name');
});

From the documentation:

This fails because requirejs needs to be sure to load and execute all
dependencies before calling the factory function above. If a
dependency array is given to define(), then requirejs assumes that all
dependencies are listed in that array, and it will not scan the
factory function for other dependencies. So, either do not pass in the
dependency array, or if using the dependency array, list all the
dependencies in it.

So if you specify a dependency array, you can't also depend on the sugar syntax to work. Not ideal in my opinion, but that's how requirejs was created to function.

此刻的回忆 2024-12-29 07:56:51

Require.js 向我的 text.js 文件发出请求,但响应是 302 - 我的用户未经过身份验证。因此,text 插件无法加载。因此,我的所有文本资源均无法加载:text!any/name.html

我的控制台给了我一条相关消息,这是我的 text 插件无法加载的另一个提示:

无法读取未定义的属性“标准化”

Require.js made a request for my text.js file, but the response was a 302 - my user was not authenticated. Therefore, text plugin couldn't load. Therefore all my text resources failed to load: text!any/name.html.

My console gave me a related message, another hint that my text plugin couldn't load:

Cannot read property 'normalize' of undefined

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文