How to import PDF.JS into Typescript using npm
我安装了PDF.JS npm程序包,并在打字稿文件中导入了该程序包,但是它不能按预期工作。 我使用以下代码将PDF.JS导入打字稿。
1 2 3 | import { PDFJSStatic } from 'pdfjs-dist'; const PDFJS: PDFJSStatic = require('pdfjs-dist'); PDFJS.getDocument('helloworld.pdf').then(console.log); |
我得到了错误
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
请提供您宝贵的建议,如果有的话,请告诉我。
在导入任何模块时,应用程序结构确实很重要,
您需要先将其导入到根级ts文件中
app.module.ts甚至在tsconfig.app.json中。