导入 PDFJS 会破坏 TS 应用程序

Importing PDFJS breaks TS application

所以我正在创建一个 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.