I'm having trouble using the fabric.js library with a Meteor app, and unfortunately I can't quite get past the stage of adding it to my app, much less invoking it. The easiest recreation is as follows:
> mrt create test
> cd test
> mkdir client
> curl -o ./client/all.js http://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.2.0/fabric.all.min.js
> mrt
Going to localhost:3000 shows the following console output:
Uncaught TypeError: Cannot read property 'object' of undefined all.js:4074
global.fabric.global.fabric all.js:4074
(anonymous function) all.js:4936
(anonymous function)
And line 4074 of all.js is the second line here:
var fabric = global.fabric || (global.fabric = { }),
extend = fabric.util.object.extend,
capitalize = fabric.util.string.capitalize,
clone = fabric.util.object.clone,
toFixed = fabric.util.toFixed,
multiplyTransformMatrices = fabric.util.multiplyTransformMatrices;
I'm pretty certain I'm doing something wrong (as opposed to the problem being with fabric or meteor) but I'm not sure where. I've also tried placing the all.js file into my public directory and, while that doesn't throw the same TypeError, it does make it so that the fabric variable seems to be unavailable anywhere in my code.
Any help with properly loading fabric.js into my app would be great.
Would you please try to put the library file into the client/compatibility subdirectory. Any javascript files imported in Meteor is wrapped in closure in which you cannot easily access the global scope. client/compatibility is the place that no closure would be applied to the library.
http://docs.meteor.com/#structuringyourapp you can find more talking about the importing library issue here.