如何在 Svelte 中使用 PDF.js (pdfjs-dist)

How to use PDF.js (pdfjs-dist) with Svelte

我正在开发一个使用 TypeScript 的精巧应用程序。我想实现像 pdf.js 这样的 PDF 查看器。我非常喜欢这个项目,所以我为它找到了一个 NPM 包 here。我安装了这个包并尝试导入 'pdfjs-dist',我收到一个错误消息:

Could not find a declaration file for module 'pdfjs-dist'. './node_modules/pdfjs-dist/build/pdf.js' implicitly has an 'any' type. Try npm install @types/pdfjs-dist if it exists or add a new declaration (.d.ts) file containing declare module 'pdfjs-dist';

我尝试安装 @types/pdfjs-dist,安装顺利,但仍然遇到该错误。我不知道为什么。我也得到了 this 回购协议,但对我要找的东西没有帮助。

我的导入

<script type = "ts" >
  import pdfjs from 'pdfjs-dist';
  import pdfjsWorkerEntry from "pdfjs-dist/build/pdf.worker.entry";
</script>

这是因为 https://github.com/mozilla/pdf.js/ 不是内置在 Typescript 中的,所以它没有类型。如果您在打字稿项目中允许它,这应该不是问题。

--allowJs 适合我 https://www.typescriptlang.org/tsconfig#allowJs