如何解决无法在 Angular 项目中使用 @types/pdfmake
我正在尝试在 Angular 应用程序中使用 JS 库 pdfmake
。为了能够使用它,我指的是 https://www.freecodecamp.org/news/how-to-use-javascript-libraries-in-angular-2-apps/ 。这利用了 @types/pdfmake
。
我已将 @types/pdfmake
安装为:
npm install --save @types/pdfmake
我在其中一个组件中使用了 pdfmake,它已按如下方式导入:
import * as pdfMake from 'pdfmake/build/pdfmake';
import * as pdfFonts from 'pdfmake/build/vfs_fonts';
(<any>pdfMake).vfs = pdfFonts.pdfMake.vfs;
为了支持我正在使用的 pdfmake 中的类型:
import * as _ from 'pdfmake';
但是在这样做时我得到了错误:
This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.
为了解决这个问题,我改变了我的 tsconfig.json 如下:
{
"compileOnSave": false,"allowSyntheticDefaultImports":true,"esModuleInterop": true,"compilerOptions": {
"baseUrl": "./","outDir": "./dist/out-tsc","sourceMap": true,"declaration": false,"downlevelIteration": true,"experimentalDecorators": true,"moduleResolution": "node","importHelpers": true,"target": "es2015","module": "es2020","lib": [
"es2018","dom"
]
}
}
但是错误 This module can only be referenced with ECMAScript imports/exports by turning on the 'allowSyntheticDefaultImports' flag and referencing its default export.
仍然存在。
编辑:
我已将 tsconfig 文件更改为以下内容:
{
"compileOnSave": false,"dom"
]
}
}
但错误仍然存在。
解决方法
在 allowSyntheticDefaultImports
内添加您 compilerOptions
它的外部,它应该可以工作。
`"compilerOptions": { "allowSyntheticDefaultImports":true,}
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。