muze
muze

Reputation: 163

How can I use FabricJs with TypeScript?

Im new in JS and want to rotate, change scale of images on canvas and coding in TypeScript using Fabric.js. as import to typescript is different with JavaScript so want to know how to import it to TypeScript. any links?

I install it like npm

install --save @types/fabric

import {fabric} from 'fabric';

And after grunt files to js there show the error:

MacBook-Pro:someName mmmr$ grunt
(node:3965) ExperimentalWarning: The http2 module is an experimental API.
Running "typescript:test" (typescript) task
> src/someName.ts(20,26): error TS1147: Import declarations in a namespace cannot reference a module.
> src/someName.ts(20,26): error TS2307: Cannot find module 'fabric'.
> src/import.ts(1,1): error TS1148: Cannot compile modules unless the '--module' flag is provided.
> src/import.ts(1,24): error TS2307: Cannot find module 'fabric'.
Warning: Task "typescript:test" failed. Use --force to continue.
Aborted due to warnings.

Any solutions for solve this problem?

Upvotes: 14

Views: 10232

Answers (3)

wangrongding
wangrongding

Reputation: 27

install @types/fabric

yarn add fabric
yarn add @types/fabric -D

then👇

import { fabric } from "fabric";

Upvotes: 1

Akashxolotl
Akashxolotl

Reputation: 566

Install using npm :-

npm install fabric --save
npm i --save-dev @types/fabric

Now import :-

import { fabric } from "fabric";

Upvotes: 12

Matt McCutchen
Matt McCutchen

Reputation: 30929

Based on the test file, it looks like the expected import is:

import { fabric } from "fabric";

Upvotes: 5

Related Questions