Reputation: 11300
I'm using RequireJS 2.1.15, and I have trouble getting the errback that I pass to the library to be executed. Here is a small sample that illustrates my problem.
define("parent", ["missing"], function(){
return new Parent();
});
require(["parent"], function(parent){
alert("parent");
}, function(err){
alert("err");
});
(corresponding fiddle at : http://jsfiddle.net/605w0ex5/2/)
When I run this code, none of the success or error functions of the require()
actually ends up called, but RequireJS prints a console message saying Error: Script error for: missing
.
My problem here is that my require()
call appears to be in limbo. It is neither successful nor failed even though one of the module it explicitly depends on will never ever be loaded. And the parent will never be loaded because a module is depends on cannot be loaded.
The problem is I DO want to be notified when my require()
call cannot be satisfied. How can I get RequireJS to actually call my errback?*
I'm having this problem on Chrome 39 and RequireJS 2.1.15.
Upvotes: 1
Views: 309
Reputation: 151411
I'm ready to call it a bug in RequireJS because a) we get the expected behavior in FF and b) if we do the following, we also get the expected behavior.
What I did is take your code and create an HTML page:
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/xhtml; charset=utf-8"/>
<script type="text/javascript" src="js/require.js"></script>
</head>
<body>
<script>
require.config({
baseUrl: "js"
});
require(["parent"], function(parent){
alert("parent");
}, function(err){
console.log(err);
alert("err");
});
</script>
</body>
</html>
The js
subdirectory contains RequireJS and a file named parent.js
, which contains:
define(["missing"], function(){
function Parent () {}
return new Parent();
});
With this setup, the errback is called as expected. I can also add the name of the module to the define
and it works with that too. But if the parent
module is created like you did, then the errback is never called.
The other thing that makes me ready to call it a bug is that in one large application of mine I rely on errbacks for proper loading of modules. The application is tested in multiple versions of FF, IE, Chrome on multiple OSes and it works. (And I use it non-optimized and optimized with r.js
.) The only thing I do not do that you code does is define a module outside of an individual file.
Upvotes: 2