Fabric.js: _fabric2.default.Canvas is not a constructor

Created on 31 May 2017  路  5Comments  路  Source: fabricjs/fabric.js

Version

1.7.11

Test Case

I am using electron-forge with node 7.9.0 i have installed fabricjs by using npm install --save everything was fine but when i try to use it i get the following error

Imgur

Steps to reproduce

maybe as i mentioned abouve

Expected Behavior

start playing with the canvas!!

Actual Behavior

i can't play with the canvas 馃槥

will be closed not adequate code sample

Most helpful comment

@Olgagr the right way to import it is

import { fabric } from 'fabric';

as a side effect fabric will be anyway appended to window, that you may or may not want to happen.

There is a specific build parameter to disable appending the object to the window.

All 5 comments

so please share some detail about electron forge and how you setup the app.
otherwise i cannot really help.woth anything.

i have fixed this by using the web version in staid of the node version.

I have the same problem using fabric in electron when installed via npm. I imported it like this:

import fabric from 'fabric';

I got an error:

Uncaught TypeError: _fabric2.default.Canvas is not a constructor

Finally, I made it work by importing it like that:

import 'fabric';

// later use it in the standard way
const canvas = new fabric.Canvas('c');

@Olgagr the right way to import it is

import { fabric } from 'fabric';

as a side effect fabric will be anyway appended to window, that you may or may not want to happen.

There is a specific build parameter to disable appending the object to the window.

@asturur Yeah, you're right. I'm not sure why I was convinced that there is a default export :)

Was this page helpful?
0 / 5 - 0 ratings

Related issues

urcoder picture urcoder  路  5Comments

bevacqua picture bevacqua  路  4Comments

medialwerk picture medialwerk  路  5Comments

f987002856 picture f987002856  路  3Comments

lyzs90 picture lyzs90  路  3Comments