angular - 在 TypeScript.2.7 中找不到名称“TextDecoder”
问题描述
我正在创建一个 Angular 6 应用程序(使用 TypeScript 2.7)并希望使用 TextDecoder 本机函数。当我运行 ng build --aot 时,我收到错误:错误 TS2304:找不到名称“TextDecoder”。
任何帮助,将不胜感激。下面是我的 tsconfig.json 文件和我的 package.json 文件中的包列表。
谢谢,鲍勃
{
"compileOnSave": false,
"compilerOptions": {
"baseUrl": "./",
"outDir": "./dist/out-tsc",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2017",
"dom"
]
}
}
"dependencies": {
"@angular/animations": "^6.0.5",
"@angular/cdk": "^6.2.1",
"@angular/common": "^6.0.3",
"@angular/compiler": "^6.0.3",
"@angular/core": "^6.0.3",
"@angular/forms": "^6.0.3",
"@angular/http": "^6.0.3",
"@angular/material": "^6.2.1",
"@angular/platform-browser": "^6.0.3",
"@angular/platform-browser-dynamic": "^6.0.3",
"@angular/router": "^6.0.3",
"bootstrap": "^4.1.1",
"core-js": "^2.5.4",
"hammerjs": "^2.0.8",
"npm": "^6.1.0",
"rxjs": "^6.0.0",
"zone.js": "^0.8.26"
},
"devDependencies": {
"@angular-devkit/build-angular": "~0.6.8",
"@angular/cli": "~6.0.8",
"@angular/compiler-cli": "^6.0.3",
"@angular/language-service": "^6.0.3",
"@types/jasmine": "~2.8.6",
"@types/jasminewd2": "~2.0.3",
"@types/node": "^10.5.7",
"codelyzer": "~4.2.1",
"jasmine-core": "~2.99.1",
"jasmine-spec-reporter": "~4.2.1",
"karma": "~1.7.1",
"karma-chrome-launcher": "~2.2.0",
"karma-coverage-istanbul-reporter": "~2.0.0",
"karma-jasmine": "~1.1.1",
"karma-jasmine-html-reporter": "^0.2.2",
"protractor": "~5.3.0",
"ts-node": "~5.0.1",
"tslint": "~5.9.1",
"typescript": "~2.7.2"
}
}
解决方案
您需要将输出包的设置更改为 ES7。转到src/tsconfig.app.json
并添加到 compilerOptions:
"compilerOptions": {
"lib": [
"es2017",
"dom"
]
}
推荐阅读
- asp.net-core - 无法在 asp.net 核心类库 (IFormFile) 中添加所需的引用
- visual-studio - Asp Net Core 2.1 未在 Visual Studio 2017 目标框架中列出
- java - 如何在没有 for 循环的情况下获取对象值并添加到 Java 中的 Arraylist
- python - 四舍五入并比较索引Python
- java - 应用程序在编辑器中运行,但不是 .exe
- asp.net-mvc-4 - 如何使用 href 中的 value 属性作为Controller Action 的参数
- python - python bitbucket 无法获取存储库(错误,'未找到服务。')
- java - 确定加载失败的类文件的路径
- ruby-on-rails - Nginx+puma 部署
- git - 强制 Git 导致合并冲突