我正在将Angular项目(使用Angular CLI创建)从2升级到4.我遵循升级说明,但现在项目不能编译,由于类似这样的错误一个:从Angular 2升级到4后出现类型错误
ERROR in /mypath/node_modules/typescript/lib/lib.dom.d.ts (6945,11):
Duplicate identifier 'Headers'.
为了进行调试,我创建了一个新的Angular 4项目,再次与CLI进行比较。新创建的项目无错地编译。
当我编译有问题的文件(lib.dom.d.ts)时,它们完全相同,但在升级的项目中,错误在VS Code中突出显示,但不在新项目中显示(left is升级后,右边是新项目):
(有趣的是,我有很多的新项目的滚动区域的红色指示灯,什么是他们试图告诉我的)
我想我可以弄清楚这两个项目之间的差异是如何解决这个问题的,但我没有找到任何解决方案。
两个项目返回
./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中删除“dom”是否可以做任何事情? – pixelbits