it was installed like this: npm install @ types / fabric --save

import { Component, OnInit } from "@angular/core"; import { Canvas } from "fabric/fabric-impl"; import fabric = require("fabric/fabric-impl"); @Component({ selector: "app-main-reconizer", templateUrl: "./main-reconizer.component.html", styleUrls: ["./main-reconizer.component.css"] }) export class MainReconizerComponent implements OnInit { private canvas: fabric.Canvas; constructor() { } ngOnInit() { this.canvas = new fabric.Canvas('c'); this.canvas.add(new fabric.IText('Hello Fabric!')); } } 

An error occurs:

 ./src/app/main-reconizer/main-reconizer.component.ts Module not found: Error: Can't resolve 'fabric/fabric-impl' in 'D:\TestPrj\else development\Angular\PRJ\recognizerWEB\src\app\main-reconizer' @ ./src/app/main-reconizer/main-reconizer.component.ts 13:13-42 @ ./src/app/app.module.ts @ ./src/main.ts @ multi (webpack)-dev-server/client?http://0.0.0.0:0 ./src/main.ts 

    1 answer 1

    In the file .angular-cli.json in the section scipts add a line with something like this

     "scripts": [ "../node_modules/you/path/to/file" ], 

    Specify the path in the node_modules to the script. If you need css, then there is also a section css, similarly connect styles.

    And re-run ng serve

    And in the file of your component before the decorator @Component add such a line

     declare const fabric: any; 

    And use the code in the fabric as you would use if you wrote on a regular JS.

    • And remove the imports - Yegor Kulik