Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Importing PDFJS breaks TS application

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?

like image 961
Chris Maness Avatar asked Jan 29 '23 21:01

Chris Maness


1 Answers

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.

like image 131
Joe Clay Avatar answered Feb 01 '23 10:02

Joe Clay