Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

fabric.Canvas is not a constructor

I've included fabric like so: <script src="js/fabric_freedrawing.js"></script>

But when I use it like this:

var canvas;

function initSketchPad() {
    canvas = new fabric.Canvas('sketch-pad', {
        isDrawingMode: true
    });

}

I get

Uncaught TypeError: fabric.Canvas is not a constructor

like image 967
JordyvD Avatar asked Aug 30 '16 11:08

JordyvD


1 Answers

I'm not sure what you have in your fabric_freedrawing.js file but adding your code to a snippet below seems to work just fine.

var canvas;
function initSketchPad() {
    canvas = new fabric.Canvas('sketch-pad', {
        isDrawingMode: true
    });
}

initSketchPad();
canvas {
  border:1px solid;
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/fabric.js/1.6.4/fabric.min.js"></script>
<canvas height=300 width=300 id="sketch-pad">
like image 68
StefanHayden Avatar answered Oct 22 '22 04:10

StefanHayden