node_modules/@types/pdfjs-dist/index.d.ts(63,39) 中的错误:错误 TS2304:找不到名称“未知”
Posted
技术标签:
【中文标题】node_modules/@types/pdfjs-dist/index.d.ts(63,39) 中的错误:错误 TS2304:找不到名称“未知”【英文标题】:ERROR in node_modules/@types/pdfjs-dist/index.d.ts(63,39): error TS2304: Cannot find name 'unknown' 【发布时间】:2020-04-24 17:46:08 【问题描述】:我在 Angular 6 项目中使用 ng2-pdf-viewer,
在项目编译时出现以下错误
node_modules/@types/pdfjs-dist/index.d.ts(63,39) 中的错误:错误 TS2304:找不到名称“未知”。 node_modules/@types/pdfjs-dist/index.d.ts(65,34):错误 TS2304:不能 查找名称“未知”。 node_modules/@types/pdfjs-dist/index.d.ts(80,31):错误 TS2304:不能 查找名称“未知”。 node_modules/@types/pdfjs-dist/index.d.ts(82,30):错误 TS2304:不能 查找名称“未知”
我的 package.json 文件如下所示
"dependencies":
"@angular/animations": "^6.1.10",
"@angular/common": "^6.1.0",
"@angular/compiler": "^6.1.0",
"@angular/core": "^6.1.0",
"@angular/forms": "^6.1.0",
"@angular/http": "^6.1.0",
"@angular/platform-browser": "^6.1.0",
"@angular/platform-browser-dynamic": "^6.1.0",
"@angular/router": "^6.1.0",
"@ngx-translate/core": "^11.0.1",
"@ngx-translate/http-loader": "^4.0.0",
"@vimeo/player": "^2.10.0",
"@types/node": "10.3.1",
"angular-6-datatable": "~0.8.0",
"angular-6-social-login": "~1.1.1",
"bootstrap": "^4.3.1",
"core-js": "^2.5.4",
"crypto-js": "~3.1.9-1",
"devextreme": "^19.1.5",
"devextreme-angular": "^19.1.5",
"font-awesome": "~4.7.0",
"jquery": "^3.4.1",
"ng2-drag-drop": "^3.0.2",
"ng2-pdf-viewer": "^6.0.2",
"ng5-slider": "^1.2.4",
"ngx-bootstrap": "^3.3.0",
"ngx-drag-scroll": "~7.4.2",
"ngx-image-cropper": "~1.3.10",
"ngx-loading": "^3.0.1",
"ngx-owl-carousel-o": "~1.1.5",
"ngx-rating": "0.0.9",
"ngx-slick-carousel": "^0.4.4",
"ngx-toastr": "~10.0.4",
"ngx-ui-loader": "^7.2.2",
"popper.js": "~1.15.0",
"rxjs": "~6.2.0",
"rxjs-compat": "^6.5.2",
"slick-carousel": "^1.8.1",
"stream": "0.0.2",
"swiper": "^4.5.0",
"zone.js": "~0.8.26"
,
"devDependencies":
"@angular-devkit/build-angular": "~0.8.0",
"@angular/cli": "~6.2.9",
"@angular/compiler-cli": "^6.1.0",
"@angular/language-service": "^6.1.0",
"@types/jasmine": "~2.8.8",
"@types/jasminewd2": "~2.0.3",
"codelyzer": "~4.3.0",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~3.0.0",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.1",
"karma-jasmine": "~1.1.2",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.4.0",
"ts-node": "~7.0.0",
"tslint": "~5.11.0",
"typescript": "~2.9.2"
这是我的 package.json 文件
【问题讨论】:
【参考方案1】:我在基于 Angular 6 的项目中遇到了类似的问题。 来自 package.json:
"dependencies":
...
"ng2-pdf-viewer": "^5.2.3",
"rxjs": "6.3.3",
,
"devDependencies":
...
"typescript": "^2.7.2"
来自 package-lock.json(第一个由 npm install 命令生成):
...
"ng2-pdf-viewer":
"version": "5.3.4",
"resolved": "_removed_",
"integrity": "_removed_",
"requires":
"@types/pdfjs-dist": "^2.0.1",
"pdfjs-dist": "^2.2.228",
"tslib": "^1.9.0"
,
...
"pdfjs-dist":
"version": "2.2.228",
"resolved": "_removed_",
"integrity": "_removed_",
"requires":
"node-ensure": "^0.0.0",
"worker-loader": "^2.0.0"
,
...
"@types/pdfjs-dist":
"version": "2.1.3",
"resolved": "_removed_",
"integrity": "_removed_"
,
...
为了解决这个问题,我在 package-lock.json 文件中将@types/pdfjs-dist 版本改为“2.1.0”。删除node_modules文件夹,然后执行“npm install”。
你可能遇到的另一个问题是
ERROR in node_modules/@types/pdfjs-dist/index.d.ts(7,1): error TS1084: Invalid 'reference' directive syntax.
要解决这个问题,打开文件“node_modules/@types/pdfjs-dist/index.d.ts”,然后在第7行附近搜索三个斜杠
/// <reference lib="dom"/>
然后删除斜线到“
// <reference lib="dom"/>
【讨论】:
【参考方案2】:您是否尝试将您的 typescript 版本更新为 3 ?
npm i -D typescript@3
或
“skipLibCheck”:真
【讨论】:
是的,我已经尝试过了,但它在 Angular Compiler 中显示错误,需要 TypeScript >=2.7.2 和 您可以尝试在您的 tsconfig 中添加 "skipLibCheck": true 并检查一次吗? 感谢@sameer,它工作正常。但是跳过库检查选项是解决这个问题的正确方法,我有点困惑。以上是关于node_modules/@types/pdfjs-dist/index.d.ts(63,39) 中的错误:错误 TS2304:找不到名称“未知”的主要内容,如果未能解决你的问题,请参考以下文章