javascript - 如何使用 npm 将 PDF.JS 导入 Typescript

标签 javascript node.js typescript npm-install pdf.js

我安装了 PDF.JS npm 包并在 typescript 文件中导入相同的包,但它没有按预期工作。我使用以下代码将 PDF.JS 导入 typescript 。

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 中。

关于javascript - 如何使用 npm 将 PDF.JS 导入 Typescript,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/47812903/

相关文章:

javascript - typescript 和等效的js代码

javascript - 使用 Angular 从下拉列表中获取选定的值

javascript - 在 Bootstrap Modal 中使用 HandsonTable 不起作用

javascript - 端点字符串保存在rails postgresql db中,无法在js前端中使用它们进行fetch()调用

javascript - 为项目列表正确声明 Observable

javascript - 没有窗口对象存在 webpack nodejs

node.js - 在 Windows Azure 上的子文件夹下托管 Ghost 博客的共享链接问题

javascript - 类型错误 : video is null - what is it?

javascript - Express 500 类型错误 : Cannot read property 'get' of undefined

javascript - 为什么 javascript 的 ES6/Harmony Set 对象会为键/值/条目方法返回空对象?