Last Updated: February 25, 2016
·
1.903K
· birox

RequireJS d3 library fix

Today I bumped into some troubles trying to load the d3.js library using Require.js, mainly all of my Require.js called scripts/modules would throw type undefined error when trying to call the d3 object, even with al require dependencies in order. Don't really know why since from my knowledge d3 library is amd compliant..

Any who, I fixed the issue with a init hack like so:


shim: {
'd3': {
exports: 'd3',
init: function() {
window.d3 = d3;
}
},
}
</pre>

From Require's point is it good, is it bad? Have no clue as i'm new to amd stuff, all i know is that it works, so if you have a lib you need need handled by Require.js and modulating gives you issues, check if the library attaches the object/function to the window or document object and try to repeat the action within the Require.js shim dependency registration of your library, init function more precisely.