VS2019错误TS2300:重复的标识符IteratorResult

时间:2019-10-21 11:46:55

标签: angular asp.net-core build visual-studio-2019

我有一个带有Angular App的ASP.NET Core项目。 将项目更新为.NET Core 3.0版本后,我遇到了问题。 在ASP.NET Core Project构建期间,我在输出中看到2个错误:

1>------ Build started: Project: Portal, Configuration: Debug Any CPU ------
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\3.6\lib.es2015.iterable.d.ts(41,6): error TS2300: Build:Duplicate identifier 'IteratorResult'.
1>D:\Solution\MyProject\ClientApp\node_modules\@types\node\index.d.ts(73,11): error TS2300: Build:Duplicate identifier 'IteratorResult'.
1>MyProject -> D:\Solution\MyProject\bin\Debug\netcoreapp3.0\Portal.dll
1>Done building project "Portal.csproj".
========== Build: 1 succeeded, 0 failed, 0 up-to-date, 0 skipped ==========

package.json:

{
  "name": "client-app",
  "version": "0.0.0",
  "scripts": {
    "ng": "ng",
    "start": "ng serve",
    "build": "ng build",
    "test": "ng test",
    "lint": "ng lint",
    "e2e": "ng e2e",
    "build-dev": "ng build --configuration=development"
  },
  "private": true,
  "dependencies": {
    "@angular/animations": "^8.2.2",
    "@angular/cdk": "~8.1.3",
    "@angular/common": "~8.2.0-next.1",
    "@angular/compiler": "~8.2.0-next.1",
    "@angular/core": "~8.2.0-next.1",
    "@angular/forms": "~8.2.0-next.1",
    "@angular/platform-browser": "~8.2.0-next.1",
    "@angular/platform-browser-dynamic": "~8.2.0-next.1",
    "@angular/router": "~8.2.0-next.1",
    "core-js": "^2.5.4",
    "primeflex": "^1.0.0-rc.1",
    "primeicons": "^1.0.0",
    "primeng": "^8.0.1",
    "rxjs": "~6.5.2",
    "tslib": "^1.9.0",
    "zone.js": "~0.9.1"
  },
  "devDependencies": {
    "@angular-devkit/build-angular": "~0.801.1",
    "@angular/cli": "~8.1.1",
    "@angular/compiler-cli": "~8.2.0-next.1",
    "@angular/language-service": "~8.2.0-next.1",
    "@types/node": "~8.9.4",
    "@types/jasmine": "~2.8.8",
    "@types/jasminewd2": "~2.0.3",
    "codelyzer": "^5.0.1",
    "jasmine-core": "~2.99.1",
    "jasmine-spec-reporter": "~4.2.1",
    "karma": "~4.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": "3.4.5"
  }
}

tsconfig.json:

{
  "compileOnSave": false,
  "compilerOptions": {
    "baseUrl": "./",
    "downlevelIteration": true,
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "module": "esnext",
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "importHelpers": true,
    "target": "es2015",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "es2018",
      "dom"
    ]
  }
}

我尝试过的:

  • 通过npm更新@ type / node;
  • 从package.json中删除@ type / node;
  • 将打字稿(package.json的底部)版本更改为3.6.4。

4 个答案:

答案 0 :(得分:4)

Angular 8希望Typescript> = 3.4.0和<3.6.0,但是Visual Studio 2019使用3.7构建。

通过在NPM和Visual Studio中安装3.5.3,我能够解决这些问题。

npm install-保存typescript@3.5

安装软件包Microsoft.TypeScript.MsBuild-版本3.5.3

此后,项目属性(“ TypeScript生成”选项卡)中的“ Typescript版本”下拉列表显示为灰色,但读取的值为3.5(NuGet)。保存,重建,一切都很好。

希望可以帮助某人。我花了4个小时来解决这个问题。

亚伦

答案 1 :(得分:3)

我在使用Vs2019和angular版本8时也遇到了完全相同的问题。我尝试按照上述建议下载并安装VS2019的TypesScript编译器3.7版。但是问题仍然存在。

按照J King的建议,升级节点类型高于或等于8.10.52版的方法可以解决上述问题。在tsconfig.json文件中,我将编译器目标版本设置为ES6。然后发出以下命令:

npm install @ types / node @ 8.10.52

然后做:

ng构建

确保其构建干净。在Vs2019中进行干净的构建。

这似乎解决了问题。

答案 2 :(得分:2)

我也遇到了类似的问题,但是从下面的链接在本地计算机上安装了Typescript之后, http://www.typescriptlang.org/#download-links

我重建解决方案,它奏效了。

注意:从下载链接中选择合适的VisualStudio版本或正在使用的任何IDE!

答案 3 :(得分:0)

我几次遇到了这个问题。一旦我能够使用@wkkhondkar推荐的方式解决该问题,另一次我意识到这个问题是因为我对SPA执行了ng run serve命令,却忘记了停止服务器。