RequireJS: finding the script responsible for an error

javascript, requirejs

Solution

Use loader level errorbacks

require(["foo","bar"],function(foo,bar){
  // perform some action
},function(error){
  // handle error here
});

Note that failed module name is given in `error.requireModules`. Such errorbacks can be used both for loaders and modules. If you have multiple fallback paths for a resource, use path fallbacks.

As per my personal experience, I humbly disagree with ddotsenko. We're using RequireJS in our production environment. If setup properly, RJS is very reliable.

Problem

I'm looking for an elegant way to find out the full path to a script that caused a timeout error (i.e. failed to load a dependency). ``` requirejs.onError = function (err) { // this works: var script_that_failed_loading = err.originalError.target.src // now I want: var the_script_responsible_for_this = <???> }; ```

Original source