Search code examples
typescriptmodularjspm

How to use cropper.js in typescript modular project?


I am using jspm install npm:cropper

which installs cropper and adds "cropper": "npm:cropper@^2.0.1" to package.json aslo i could find it under \jspm_packages\npm folder

But its not loading in network tab. any idea what am missing?

P.S:- I did not find the type definitions for cropper.js so i have declared the cropper like

declare var cropper: any;
declare module "cropper" {
    export = cropper;
}

and imported it as import * as cropper from 'cropper'; which is not giving any error, but still no luck with cropper loading.


Solution

  • There are two steps. The first step is to install cropper which is what you did when you added the package to package.json. The second step is to actually load the package - see https://github.com/systemjs/systemjs how to do that.

    If you want to import the package yourself, you should not use import ... from 'cropper'but

    var cropper = require('cropper');
    

    because otherwise TypeScript compiler will check if the module is written in TypeScript and if it is located under node_packages folder.