angular - 导入 PDFJS 会破坏 TS 应用程序

标签 angular typescript pdf.js

所以我正在创建一个 Angular 2 - typescript 应用程序,我希望能够使用 Mozilla 的 PDFJS 库浏览 PDF。我已经像这样安装了依赖项:

npm install pdfjs-dist @types/pdfjs-dist --save

然后在我的 app.modules.ts 中,我尝试像这样导入它:

import { PDFJS } from "pdfjs-dist";

我在尝试运行 tsc 时遇到以下错误,我得到以下输出:

src-ng/csm/app/app.module.ts(27,10): error TS2305: Module '"pdfjs-dist"' has no exported member 'PDFJS'.

我很茫然,因为 pdfjs-dist 的输入似乎是有序的。还有什么我应该包括的吗?

最佳答案

你必须像这样导入它:

import * as PDFJS from "pdfjs-dist";

// or individual members

import { getDocument } from "pdfjs-dist";

This is due to the way TypeScript handles interop between the old module specs (CommonJS, UMD, AMD) and ES6 modules.

关于angular - 导入 PDFJS 会破坏 TS 应用程序,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45467843/

相关文章:

typescript - 在单一类型参数上使用接受的混合类型

javascript - 引用错误 : PDFJS is not defined when loading a pdf

angular - 如何将 AMD 与 angular-cli 一起使用?

javascript - Observables - Angular - .map 不起作用,但 .subscribe 起作用

reactjs - Pick<S, K> 带有动态/计算键的类型

typescript - 在 VS Code 中隐藏 .js 和 .map 文件

javascript - 手动调用 PDFJS 函数。 PDFView.open 渲染后调用什么函数

javascript - 显示 pdf 的搜索文本以及页码

angular - ng-template 错误 : The template context does not define a member called . ..(剑道网格)

angular - 我怎样才能只预加载其 parent 已被激活的模块?