Typescript | TypeError: __WEBPACK_IMPORTED_MODULE_1_signature_pad__ is not a constructor

主宰稳场 提交于 2019-12-10 10:01:58

问题


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

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

// .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 I launch the browser page: ERROR Error: Uncaught (in promise): TypeError: WEBPACK_IMPORTED_MODULE_1_signature_pad is not a constructor

I've also tried using dimpu's angular2-signature-pad, but the same error essentially comes up.


回答1:


Provided you have the typings for signature_pad (npm install --save-dev @types/signature_pad), it has to be imported and used like below as signature_pad does not have any exported members and only declares the class SignaturePad into the current scope:

import 'signature_pad';

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


来源:https://stackoverflow.com/questions/44172211/typescript-typeerror-webpack-imported-module-1-signature-pad-is-not-a-con

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!