Javascript 已忽略超时的RequireJS本地错误回调

Javascript 已忽略超时的RequireJS本地错误回调,javascript,requirejs,Javascript,Requirejs,如果所需的任何文件的响应时间超过等待时间,则会中断应用程序,并且不会进入我定义的任何错误回调 require.config({ waitSeconds: 1, catchError: { define: true } }); require.onError = function() { // Does not reach here }; require(['http://localhost/remote-file-that-does-not-res

如果所需的任何文件的响应时间超过等待时间,则会中断应用程序,并且不会进入我定义的任何错误回调

require.config({
    waitSeconds: 1,
    catchError: {
        define: true
    }
});
require.onError = function() {
    // Does not reach here
};
require(['http://localhost/remote-file-that-does-not-respond-for-more-than-config-wait-time.js'], function() {}, function() {
    // Err callback never triggers
});
应用程序将崩溃,控制台将记录:

Uncaught Error: Load timeout for modules: remote-scripts!,http://localhost/remote-file-that-does-not-respond-for-more-than-config-wait-time.js http://requirejs.org/docs/errors.html#timeout
然而,如果有404响应,则错误回调工作正常:

require(['http://localhost/external-file-that-does-not-exist.js'], function() {}, function() {
    // Err callback does trigger
});

为什么当服务器没有响应时,它不会触发本地错误回调,甚至不会到达全局错误回调?

您应该设置
强制定义:true
。否则,RequireJS可能无法检测到某些超时。文件