Typescript | TypeError: __WEBPACK_IMPORTED_MODULE_1_signature_pad__ is not a constructor

I am currently working on an Angular2 project and I am trying to use the JS library ( https://github.com/szimek/signature_pad ) for a signature input.

I've tried using the library as is, with my code like this:

// .ts file
import * as SignaturePad from 'signature_pad';

export class ... {
    private signaturePad: SignaturePad;

    ngOnInit() {
        let canvas = document.querySelector("canvas");
        this.signaturePad = new SignaturePad(canvas);
    }
}

      

...

// .html file
<div...>
    <canvas></canvas>
</div>

      

and I get the following error when launching the browser page: ERROR: not available (in a promise): TypeError: WEBPACK_IMPORTED_MODULE_1_signature_pad is not a constructor

I have also tried using the angular2-signature-pad dimpu, but the same error mostly occurs.

+3


source to share


1 answer


If you have typing for signature_pad

( npm install --save-dev @types/signature_pad

), you need to import and use it as shown below, since signature_pad

it has no exported members and declares a class SignaturePad

in the current scope:



import 'signature_pad';

// ...
let canvas = document.querySelector("canvas");
this.signaturePad = new SignaturePad(canvas);

      

+2


source







All Articles