Closed madarche closed 11 years ago
I'm not sure how exactly AMD tries to handle CJS style require's. Maybe the issue is that you prepared Deferred as AMD module and try to require it a CJS (?)
Try to require deferred traditional AMD way, it definitely should work:
define(['./js/lib/deferred'], function (deferred) {
'use strict';
// ...
});
I'm closing it, but reopen if you still have issue
I have added in https://github.com/madarche/deferred-tests/tree/master/browser_amd_requirejs a new test: index2.html using the traditional AMD way.
And it produces the exact same error:
TypeError: deferred is not a function
http://example.net/js/test2.js
Line 8
Could you try to run those 2 tests yourself please? It's straightforward, those files just need to be set up at the root of a web site.
Thank you!
Ok, I get it.
Issue is that you require ./js/lib/deferred
but module defines itself as deferred
.
It's AMD quirk, to have it work, you should either:
--name
optionI'd go with first option, and I'll remove usage of --name
(in case of AMD), from example in documentation.
See: http://requirejs.org/docs/api.html#modulename
It's bad that I added name
in AMD generation example. I'll improve it in a minute
Creating the deferred.js AMD module without the --name
option was the solution indeed. It now works like a charm and we can work cleanly with deferred both on the server side and the client side. It's a real pleasure.
Thanks a lot!
You're welcome!
Here is the error :
The problem arises when requiring deferred from a sub-directory :
The problem doesn't arise when requiring deferred from the same directory :
Here is the code : https://github.com/madarche/deferred-tests/tree/master/browser_amd_requirejs
I have prepared the deferred.js as documented :
And I'm testing with an up-to-date Firefox.
I have also "packed" deferred with browserify without any success.
I have no idea if the problem comes from deferred or from require.js.
Could you have a look please?