requirejs does not clean up properly before calling onError #156

kensaggy opened this Issue Dec 30, 2011 · 1 comment


None yet

2 participants


When an error occurs, requirejs does not clean up properly before calling onError, and so when calling require() inside an onError handler nothing happens.

example code:

require.onError = function(err) {
    console.log(err); //temporary until error handler loads (or if it fails too)

require(['errorhandler'] ,function(errorhandler) { 
        require.onError = errorhandler; 

require(['require','domReady','app'], function(require, domReady, App) 
        domReady(function() { 
                console.log('DOM IS READY! GO!'); 

define(['require'],  function () { 
        return (function(errObject) { 
                function handleTimeouts(modules) { 
                        for ( k in modules ) { 
                                switch (modules[k]) { 
                                        case "jquery": { 
                                                console.log('It seems jquery timedout, lets fall back to local 
                                                require(['libs/jquery/1.7.1/jquery-1.7.1'], function($) { // 
trying to load the local copy 
                                                        console.log('jquery has been loaded from local' , $.fn.jquery); 
                                        //Add more modules here to handler their fallback procedure. 
                                        default: { 
                                                console.log('I do not know this library [',modules[k],'] - can 
\'t do anything to recover'); 
                requireType = errObject.requireType; 
                requireModules = errObject.requireModules.trim().split(' '); 
                if (requireType == "timeout") { 

When this is ran (and i simulate a jquery 'require' failing to load, using a typo
in the url of the cdn version), the error handlers reaches up to the
"It seems jquery timedout," message, and stops there, never trying to
run that "require" statement that follows.

I think this is an important bug since it will allow developers to have somewhat of a fallback/recovery strategy on errors.

See discussion in google group at :
As seen in the discussion thread, possible just make sure that require can be re-run and not take care of clean up/removing old script tags (the script tag that failed) at the moment

Thanks in advance,



It also doesn't call $.holdReady(false) to allow the DOM ready event to occur, which may be needed by the error handler.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment