I have been using FabricJS 2.0 rc-3 and Angular 5.0.3 and they worked well together, but now I'm starting a new project and used the current latest stable FabricJS 2.1 and Angular 5.2.7 and they do not work.
This is how I imported Fabric and worked with it earlier without any issue:
import { fabric } from 'fabric';
this.canvas = new fabric.StaticCanvas('map-canvas', { renderOnAddRemove: false });
In the new project with the new versions this does not work. It compiles, but at runtime I get this:
ERROR TypeError: Cannot read property 'Canvas' of undefined
I also tried the following import, but that doesn't even compile:
/* import 'fabric';
// declare const fabric: any; */
I searched the web up and down, but haven't found any clue about how to fix this.
Package.json:
{
"name": "atlas-project",
"version": "0.9.6",
"license": "MIT",
"scripts": {
"ng": "ng",
"start": "ng serve",
"build": "ng build",
"build-prod": "node ./build.version.js $CI_BUILD_NUMBER && ng build --environment prod --target=production --aot",
"build-staging": "node ./build.version.js $CI_BUILD_NUMBER && ng build --environment staging --target=production --aot",
"test": "ng test",
"lint": "ng lint",
"e2e": "ng e2e"
},
"private": true,
"dependencies": {
"@angular/animations": "^5.2.7",
"@angular/common": "^5.2.7",
"@angular/compiler": "^5.2.7",
"@angular/core": "^5.2.7",
"@angular/forms": "^5.2.7",
"@angular/http": "^5.2.7",
"@angular/platform-browser": "^5.2.7",
"@angular/platform-browser-dynamic": "^5.2.7",
"@angular/router": "^5.2.7",
"@ng-bootstrap/ng-bootstrap": "^1.0.0",
"@types/google.analytics": "0.0.36",
"@types/ramda": "^0.24.18",
"ajv": "^6.2.1",
"angularfire2": "^5.0.0-rc.6",
"bootstrap": "^4.0.0",
"core-js": "^2.4.1",
"fabric": "^2.1.0",
"firebase": "^4.10.1",
"font-awesome": "^4.7.0",
"jsoneditor": "^5.11.0",
"jw-bootstrap-switch-ng2": "^1.0.8",
"node-sass": "^4.7.2",
"ramda": "^0.25.0",
"rxjs": "^5.5.6",
"zone.js": "^0.8.14"
},
"devDependencies": {
"@angular/cli": "^1.7.2",
"@angular/compiler-cli": "^5.2.7",
"@angular/language-service": "^5.2.7",
"@types/jasmine": "~2.5.53",
"@types/jasminewd2": "~2.0.2",
"@types/node": "^6.0.92",
"codelyzer": "^4.2.1",
"jasmine-core": "~2.6.2",
"jasmine-spec-reporter": "~4.1.0",
"karma": "~1.7.0",
"karma-chrome-launcher": "~2.1.1",
"karma-cli": "~1.0.1",
"karma-coverage-istanbul-reporter": "^1.2.1",
"karma-jasmine": "~1.1.0",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.1.2",
"replace-in-file": "^3.0.0",
"ts-node": "~3.2.0",
"tslint": "~5.7.0",
"typescript": "^2.4.2"
}
}