【发布时间】:2017-04-30 23:57:54
【问题描述】:
我正在将一个 Angular 项目(使用 Angular CLI 创建)从 2 升级到 4。我已按照升级说明进行操作,但现在该项目无法编译,因为这样的类型错误:
ERROR in /mypath/node_modules/typescript/lib/lib.dom.d.ts (6945,11):
Duplicate identifier 'Headers'.
为了进行调试,我再次使用 CLI 创建了一个新的 Angular 4 项目来进行比较。新创建的项目编译没有错误。
当我编译有问题的文件(lib.dom.d.ts)时,它们完全相同,但是在升级的项目中,错误在VS Code中突出显示,但在新项目中没有(左边是升级的,右边是新项目):
(有趣的是,我在新项目的滚动区域中有很多红色指示器,它们想告诉我什么?)
我想我可以弄清楚这两个项目之间有什么区别来解决这个问题,但我没有找到任何区别。
两个项目都返回
./node_modules/tslint/bin/tslint -v
4.5.1
./node_modules/typescript/bin/tsc -v
Version 2.2.1
ng -v
@angular/cli: 1.0.0
node: 7.4.0
os: darwin x64
@angular/animations: 4.0.0
@angular/common: 4.0.0
@angular/compiler: 4.0.0
@angular/compiler-cli: 4.0.0
@angular/core: 4.0.0
@angular/forms: 4.0.0
@angular/http: 4.0.0
@angular/platform-browser: 4.0.0
@angular/platform-browser-dynamic: 4.0.0
@angular/platform-server: 4.0.0
@angular/router: 4.0.0
@angular/cli: 1.0.0
tsconfig.json 相同:
{
"compileOnSave": false,
"compilerOptions": {
"outDir": "./dist/out-tsc",
"baseUrl": "src",
"sourceMap": true,
"declaration": false,
"moduleResolution": "node",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"target": "es5",
"typeRoots": [
"node_modules/@types"
],
"lib": [
"es2016",
"dom"
]
}
}
那么问题:还有什么可能导致行为差异?
【问题讨论】:
-
查看core-js的版本是否相同。从 tsconfig 中的“lib”中删除“dom”有什么作用吗?
标签: angular typescript