簡體   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