我一直在使用 FabricJS 2.0 rc-3 和 Angular 5.0.3,它们一起工作得很好,但现在我开始一个新项目并使用当前最新的稳定 FabricJS 2.1 和 Angular 5.2.7,但它们不起作用。
这就是我之前导入 Fabric 并使用它的方式,没有任何问题:
import { fabric } from 'fabric';
this.canvas = new fabric.StaticCanvas('map-canvas', { renderOnAddRemove: false });
在具有新版本的新项目中,这不起作用。它编译,但在运行时我得到这个:
ERROR TypeError: Cannot read property 'Canvas' of undefined
我也尝试了以下导入,但它甚至没有编译:
/* import 'fabric';
// declare const fabric: any; */
我在网上上下搜索,但没有找到有关如何解决此问题的任何线索。
包.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"
}
}