繁体   English   中英

打字稿导入和Webpack

[英]Typescript import and Webpack

我正在尝试使用TypeScript应用程序中的hellosign嵌入式模块,然后使用Webpack将其打包并作为网页的一部分运行。

我还导入了@types

问题是,如果我使用:

import * as HelloSign from "hellosign-embedded";

Typescript给我一个错误:

error TS2306: File 'D:/Work/ProjectX/node_modules/@types/hellosign-embedded/index.d.ts' is not a module.

我也尝试过简单地使用:

import "hellosign-embedded";

这使我可以从我的代码访问全局的HelloSign ,但是问题是,在运行webpack后,在浏览器中运行它时, HelloSign

Uncaught ReferenceError: HelloSign is not defined
    at HTMLDocument.<anonymous> (onboarding.tsx:10)
    at mightThrow (jquery.js:3570)
    at process (jquery.js:3638)

导入该库的正确方法是什么? 提供的类型是否有问题?

这样做对我有用:

   import HelloSign = require("hellosign-embedded");

   console.log(HelloSign.init);

转到定义文件: node_modules/@types/hellosign-embedded/index.d.ts

将此添加到文件末尾:

export = HelloSign;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM