RequireJS 和文本插件模块加载超时
我在使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
我猜这是一个路径问题。我有相同的设置(节点/快递和主干),它似乎对我有用。这是我的 main.js 文件:
这是我从模块内调用插件的方法:
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:
and here is how I call the plugin from within a module:
由于它在 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
我原来的答案
我在这里回答了一个类似的问题指向官方require.js 故障排除页面。
就我而言,仅当在单个 MacBook 上的多个 Chrome 版本的 Chrome 上打开开发者控制台时,才会出现此错误。其他设备没有出现这个问题。因此,我可以通过更改那台计算机上的配置来确定。
waitSeconds
waitSeconds 选项 可以配置为无限 (0) 或您指定的任何值想要(以秒为单位)。默认值为 7 秒。示例配置:
由于无限 (0) 禁用超时,我不建议在生产代码中使用此选项!如果您在任何地方运行代码时遇到此问题或禁用超时没有帮助,请继续阅读。
导致此问题的 3 个常见原因
paths
和baseUrl
选项)有关此主题的更多信息检查顶部链接的原始答案。
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:
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
paths
andbaseUrl
option)For more on this topic check the original answer linked on top.
我在错误地使用语法糖时收到此错误。
您不能既定义依赖项又使用
require
工厂函数。来自文档:
因此,如果您指定依赖项数组,则不能同时依赖糖语法来工作。我认为这并不理想,但这就是 requirejs 的创建方式。
I got this error when incorrectly using the syntax sugar.
You can't both define dependencies and use the
require
factory function.From the documentation:
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.
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 a302
- 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: