angularfabricjs

Fabricjs won't initialize - Angular v18


As in the title, I have installed all required packages with no problems.

When I import fabric like so:

import  { fabric }  from 'fabric';

I get following command line error:

TS2305: Module '"fabric"' has no exported member 'fabric'.

I guess it might be issue with wrong import but I cannot find answer anywhere.


Solution

  • You might be using V6 of fabric.js, go for the below import, as per the documentation.

    import * as fabric from 'fabric'; // v6
    import { fabric } from 'fabric'; // v5
    

    You can also try to import the individual items using the below import.

    import { Canvas, Rect } from 'fabric'; // browser
    import { StaticCanvas, Rect } from 'fabric/node'; // node