Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Image-Editor in Vue.js (Vue 3.x): TypeError: Cropper2 is not a constructor #3199

Closed
GonzaloHirschToptal opened this issue Sep 15, 2021 · 3 comments · Fixed by #3218
Closed
Assignees
Labels
Bug Vue Regards integration with Vue.js

Comments

@GonzaloHirschToptal
Copy link

GonzaloHirschToptal commented Sep 15, 2021

I'm working on a Vite app that implements Uppy and one of the features we want to include is the Image Editor. I'm using @uppy/vue in order to integrate the Dashboard without having to implement it myself.

The dashboard works properly, but when clicking the edit button I get the error TypeError: Cropper2 is not a constructor, and any subsequent edits to the image trigger errors.

My configuration is:

<template>
  <dashboard
    :uppy="uppy"
    :plugins="['ImageEditor']"
    :props="{
      theme: 'light',
      metaFields: [{ id: 'name', name: 'Name', placeholder: 'File name' }],
    }"
  />
</template>

<script>
import { Dashboard } from "@uppy/vue";
import ImageEditor from "@uppy/image-editor";
import Uppy from "@uppy/core";

export default {
  name: "UppyUpload",
  components: {
    Dashboard
  },
  computed: {
    uppy: () =>
      new Uppy().use(ImageEditor, {
        quality: 0.8,
        cropperOptions: {
          viewMode: 1,
          background: false,
          autoCropArea: 1,
          responsive: true,
          croppedCanvasOptions: {}
        },
        actions: {
          revert: true,
          rotate: true,
          granularRotate: true,
          flip: true,
          zoomIn: true,
          zoomOut: true,
          cropSquare: true,
          cropWidescreen: true,
          cropWidescreenVertical: true
        }
      })
  },
  beforeUnmount() {
    this.uppy.close();
  }
};
</script>

Versions are:

"@uppy/core": "^2.0.2",
"@uppy/image-editor": "^1.0.1",
"@uppy/vue": "^0.4.0",
"vue": "3.2.11",
@GonzaloHirschToptal GonzaloHirschToptal changed the title Image-Editor: TypeError: Cropper2 is not a constructor Image-Editor in Vue.js: TypeError: Cropper2 is not a constructor Sep 15, 2021
@Murderlon Murderlon added Vue Regards integration with Vue.js and removed Triage labels Sep 15, 2021
@GonzaloHirschToptal GonzaloHirschToptal changed the title Image-Editor in Vue.js: TypeError: Cropper2 is not a constructor Image-Editor in Vue.js (Vue 3.x): TypeError: Cropper2 is not a constructor Sep 17, 2021
@aduh95 aduh95 self-assigned this Sep 20, 2021
@aduh95
Copy link
Member

aduh95 commented Sep 20, 2021

Could you share the full stack trace please?

@GonzaloHirschToptal
Copy link
Author

Could you share the full stack trace please?

It's a console error from the browser. Whenever the Image Loader loads an image to edit I get this error and the Dashboard becomes unresponsive.

Uncaught (in promise) TypeError: Cropper2 is not a constructor
    at Editor.componentDidMount (Editor.js:50)
    at index.js:274
    at Array.some (<anonymous>)
    at index.js:272
    at Array.some (<anonymous>)
    at z (index.js:267)
    at S (render.js:64)
    at UIPlugin.js:84
    at UIPlugin.js:37
    
componentDidMount | @ | Editor.js:50
  | (anonymous) | @ | index.js:274
  | (anonymous) | @ | index.js:272
  | z | @ | index.js:267
  | S | @ | render.js:64
  | (anonymous) | @ | UIPlugin.js:84
  | (anonymous) | @ | UIPlugin.js:37
  | Promise.then (async) |   |  
  | (anonymous) | @ | UIPlugin.js:31
  | update | @ | UIPlugin.js:144
  | (anonymous) | @ | index.js:368
  | iteratePlugins | @ | index.js:1146
  | updateAll | @ | index.js:367
  | (anonymous) | @ | index.js:328
  | (anonymous) | @ | index.js:50
  | _publish2 | @ | index.js:49
  | setState | @ | index.js:35
  | setState | @ | index.js:379
  | setPluginState | @ | BasePlugin.js:30
  | Dashboard.openFileEditor | @ | index.js:165
  | onClick | @ | index.js:163
  | I | @ | props.js:153

Upon inspection of the referenced lines, it seems that the line throwing an error is:
this.cropper = new Cropper(this.imgElement, opts.cropperOptions);

aduh95 added a commit that referenced this issue Sep 28, 2021
#3218)

* @uppy/image-editor: add workaround for when `Cropper` is loaded as ESM

Fixes: #3199

* Update packages/@uppy/image-editor/src/Editor.js

Co-authored-by: Kevin van Zonneveld <kevin@vanzonneveld.net>

* Add backlog entry

Co-authored-by: Kevin van Zonneveld <kevin@vanzonneveld.net>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Vue Regards integration with Vue.js
Projects
None yet
Development

Successfully merging a pull request may close this issue.

5 participants
@Murderlon @aduh95 @ajkachnic @GonzaloHirschToptal and others