2
votes

I installed the PDF.JS npm packages and import the same in typescript file, but it does not work as expected. I used the below code to import the PDF.JS into typescript.

import { PDFJSStatic } from 'pdfjs-dist';
const PDFJS: PDFJSStatic = require('pdfjs-dist');
PDFJS.getDocument('helloworld.pdf').then(console.log);

and I am getting the error

Severity Code Description Project File Line Suppression State Error TS2307 Cannot find module 'pdfjs-dist'. app.ts 2 Active Severity Code Description Project File Line Suppression State Error TS2304 Cannot find name 'require'. app.ts 3 Active

please provide your valuable suggestion and let me know what I am missed in it if any.

1

1 Answers

1
votes

App structure really matters while importing any modules, you need to import this first into your root level ts file app.module.ts and even in tsconfig.app.json.