wagster
wagster

Reputation: 538

Unexpected results with npm fabric

I've got Browserify to bundle up jquery and fabric nicely into the build using npm versions of both - I can see them both and jquery seems to be working fine. Fabric is being a bit weird though - requiring it seems to return a fabric object containing another fabric object. I have a very basic module that does this:

var $ = require('jquery');
var fabric = require('fabric');


$(document).ready(function(){

    var canvas = new fabric.Canvas('fpCanvas');

});

But I just get

Uncaught TypeError: fabric.Canvas is not a constructor

However when I do

var $ = require('jquery');
var fabric = require('fabric');


$(document).ready(function(){

    var canvas = new fabric.fabric.Canvas('fpCanvas');

});

Everything works fine. Am I requiring it the wrong way? It's not a show-stopper as I can always call fabric.fabric throughout the application, but it's inelegant and a sign that something isn't quite right...

Upvotes: 0

Views: 42

Answers (1)

J. Titus
J. Titus

Reputation: 9690

You could always do this:

var fabric = require('fabric').fabric;

// ...

var canvas = new fabric.Canvas('fpCanvas');

Upvotes: 1

Related Questions