Importing PDFJS breaks TS application

房东的猫 提交于 2019-12-13 14:15:21

问题


So I'm creating an Angular 2 - typescript application and I want to be able to explore PDFs using Mozilla's PDFJS library. I have installed the depenedencies like so:

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

Then in my app.modules.ts I attempt to import it like so:

import { PDFJS } from "pdfjs-dist";

And I'm met with the following error when trying to run tsc I get the following output:

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

I'm at a loss because it appears that the pdfjs-dist typing appears to be in order. Is there something else I should include?


回答1:


You have to import it like this:

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.



来源:https://stackoverflow.com/questions/45467843/importing-pdfjs-breaks-ts-application

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!