Fabric.js - Moving image loaded from url receiving error: Cannot read property 'length' of undefined

Fabric.js - Moving image loaded from url receiving error: Cannot read property 'length' of undefined

我是 fabric.js 的新手,我尝试将其添加到 React 应用程序中。我在 window 上创建了 canvas,因此它将是全局的并且可从所有组件使用:

window.fabricCanvas = new Fabric.fabric.Canvas();

单击 'Add Image' 按钮时,将调用以下函数:

addImage() {
Fabric.fabric.Image.fromURL(this.state.imageUrl, function(img) {
  let oImg = img.set({left: 50, top: 100, angle: -15}).scale(0.5);
  window.fabricCanvas.add(oImg).renderAll();
  window.fabricCanvas.setActiveObject(oImg);
})};

图像确实已加载,但如果我尝试 moving\scaling 图像它就会消失,并且我在控制台中收到此错误:

Cannot read property 'length' of undefined at klass._render (fabric.js:18795)

在他们的代码中引用了这一行:

if (this.isMoving === false && this.resizeFilters.length && this._needsResize()) {

知道我的代码有什么问题吗?

我在使用 2.0.0-beta2 时遇到了同样的问题,但它在稳定版 1.7.11 上运行良好,所以请尝试切换到该版本。