简体   繁体   English

打字稿导入和Webpack

[英]Typescript import and Webpack

I am trying to use the hellosign-embedded module from my TypeScript application, which is then packaged using Webpack and run as part of a web page. 我正在尝试使用TypeScript应用程序中的hellosign嵌入式模块,然后使用Webpack将其打包并作为网页的一部分运行。

I've also imported the @types typings . 我还导入了@types

The problem is that if I use: 问题是,如果我使用:

import * as HelloSign from "hellosign-embedded";

Typescript gives me an error: Typescript给我一个错误:

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

I've also tried simply using: 我也尝试过简单地使用:

import "hellosign-embedded";

Which gives me access to the HelloSign global from my code, but the problem then is that after running webpack, when running it in the browser, HelloSign is not found: 这使我可以从我的代码访问全局的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)

What's the proper way to import this library? 导入该库的正确方法是什么? Is there a problem with the typings provided? 提供的类型是否有问题?

do this it works for me : 这样做对我有用:

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

   console.log(HelloSign.init);

go to the definition file : node_modules/@types/hellosign-embedded/index.d.ts 转到定义文件: node_modules/@types/hellosign-embedded/index.d.ts

add this to the end of file : 将此添加到文件末尾:

export = HelloSign;

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

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