TypeError: Cropper is not a constructor

See original GitHub issue

Hey,

First thx for the amazing library.

I tried to update my Ionic2/Angular2 project from Cropperjs 0.7.2 (who works like a charm) to the last version of Croppersjs 0.8.1.

After this updated I’m now facing at runtime the following error:

browser_adapter.js:84 EXCEPTION: TypeError: Cropper is not a constructor

Could you please help me to fix the problem?

My code

<div id="preview" *ngIf="imgURI != null">
     <img (load)="imageLoaded()" [src]="imgURI" #imageSrc>
 </div>

 import * as Cropper from 'cropperjs';
....
@ViewChild('imageSrc') input: ElementRef;
 ....
imageLoaded() {
    this.cropper = new Cropper(this.input.nativeElement, {
        viewMode: 3,
        aspectRatio: 1 / 1,
        dragMode: 'move',
        modal: true,
        guides: false,
        highlight: true,
        background: true,
        autoCrop: true,
        autoCropArea: 0.9,
        responsive: true,
        crop: (e:any) => {

        }
    });
}

also not, I use the typings typescript definition (dt~cropperjs)

Thx in advance

Issue Analytics

  • State:closed
  • Created 7 years ago
  • Reactions:1
  • Comments:27 (1 by maintainers)

github_iconTop GitHub Comments

6reactions
sosnetcommented, Feb 14, 2017

Ok, I had to import it via import Cropper = require('cropperjs');. It’s working now.

4reactions
fengyuanchencommented, Sep 25, 2016
import Cropper from 'cropperjs';

Or

import { Cropper } from 'cropperjs';
Read more comments on GitHub >

github_iconTop Results From Across the Web

Error while initializing cropper.js - Stack Overflow
Cropper statement.when i reload the page i got another error Uncaught TypeError: Cropper is not a constructor.but in this way only they are ......
Read more >
Javascript – Error while initializing cropper.js - iTecNote
var Cropper = window.Cropper statement.when i reload the page i got another error Uncaught TypeError: Cropper is not a constructor.but in this way...
Read more >
cropper is not a constructor
TypeError: Cropper is not a constructor #94. Closed And import * as Cropper from 'cropperjs'; gives the its not a constructor . This...
Read more >
TypeError: "x" is not a constructor - JavaScript - MDN Web Docs
The JavaScript exception "is not a constructor" occurs when there was an attempt to use an object or a variable as a constructor,...
Read more >
cropperjs - npm
Just hold the Shift key when you crop on the image. Notes. The size of the cropper inherits from the size of the...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found