ded / bonzo

library agnostic, extensible DOM utility
Other
1.32k stars 137 forks source link

Bonzo produces duplicate named modules when compiled with r.js #98

Closed commuterjoy closed 11 years ago

commuterjoy commented 12 years ago

Hi,

Bonzo (and Reqwest + Qwery) all produce an empty named AMD module when used with r.js

They all produces this after compilation, alongside the original module :-

define("bonzo",[], function(){}); 

Test case, https://github.com/guardian/requirejs-optimiser-bug

requirejs (client-side) conveniently ignores this, but curl and almond throw exceptions due to duplicate module names.

So, I think r.js is misinterpreting this line for some reason,

else if (typeof context['define'] == 'function' && context['define']['amd']) define(name, definition)

Various other modules (Eg, bean etc.) don't have this problem.

I'm using the latest r.js package,

r.js -v
r.js: 2.0.6, RequireJS: 2.0.6

Thanks, M

rvagg commented 12 years ago

I'd be happy to remove the name from the define in Bonzo but I'll have to bug @ded to get it sorted out in Reqwest and Qwery. Thanks for raising this issue.

commuterjoy commented 12 years ago

@rvagg great, that would be very helpful.

ded commented 11 years ago

hey @commuterjoy (and @rvagg )

according to amd's define method, it looks like this:

define(['someModule'] , function (myMod) {
    return function () {};
});

it even says so on the RequireJS website on why amd

so what i don't get is, how this works with bean (which is doing it wrong), and not bonzo, qwery, and reqwest.

ded commented 11 years ago

ok, really trying to get this right.

have a look at this too: http://requirejs.org/docs/api.html#defdep

from what it looks like, the define method can have a first arg which is an array of dependencies. and in that case, bonzo has no dependencies...... which means we can switch it out to look like bean.

ded commented 11 years ago

alright folks. this has been fixed and i verified it to be working https://github.com/ded/bonzo/commit/d757fe64026b93bfde2a55c5f4f6ed8bf456ca99#L0R8

i added require.js in the integration folder to verify that it does in fact work :+1:

cheers