I have a requirement when I need to pass a list of modules to a plugin and load it and do some work. If I have been given a module that I cannot load, I must report the error and go to the rest of the list. I am stuck because I canβt figure out how to recover due to a failure in a failed module. Is there any other technique that I can use to meet this requirement? Here is an example that solves the problem without all my other requirements, I need to recover from failure to load my / thing2:
define("my/thing", [], function() { return 'thing'; }); define("my/loader", [], function() { return { load: function(mid, require, callback) { console.log('inside load', arguments); // is there some way to recover when this require fails // or some other technique I can use here? try { require([mid], function(mod) { console.log('inside require, mod=', mod); callback(mod); }); } catch (error) { // never gets here, when the require fails everything just stops console.log(error); callback("failed to load " + mid); } } } }); require(["my/loader!my/thing"], function(loaded) { console.log('loaded', loaded); }); require(["my/loader!my/thing2"], function(loaded) { console.log('loaded', loaded); });
source share