【问题标题】:VS2019 error TS2300: Duplicate identifier IteratorResultVS2019 错误 TS2300:重复标识符 IteratorResult
【发布时间】:2021-09-28 16:23:51
【问题描述】:

我有一个带有 Angular App 的 ASP.NET Core 项目。 将项目更新到 .NET Core 3.0 版本后,我遇到了问题。 在 ASP.NET Core 项目构建期间,我在输出中看到 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;
  • 将 typescript(package.json 的底部)版本更改为 3.6.4。

【问题讨论】:

  • 谢谢,我看到了。但是这个问题没有获得批准的决定,也没有可行的解决方案。
  • 我遇到了完全相同的错误,必须将节点类型升级到“@types/node”的最小值:“8.10.52”才能解决

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


【解决方案1】:

我也遇到了与 Vs2019 和 Angular 版本 8 完全相同的问题。我已尝试按照上面的建议为 VS2019 下载和安装 TypesScript 编译器版本 3.7。但问题依然存在。

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

npm install @types/node@8.10.52

然后做:

构建

确保它干净地构建。在 Vs2019 中做一个干净的构建。

这似乎解决了问题。

【讨论】:

    【解决方案2】:

    Angular 8 需要 Typescript >= 3.4.0 和

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

    npm install --save typescript@3.5

    安装包 Microsoft.TypeScript.MsBuild -Version 3.5.3

    之后,项目属性(TypeScript Build 选项卡)中的 Typescript 版本下拉菜单显示为灰色,但读取的正确值为 3.5 (NuGet)。保存、重建,一切都很好。

    希望对某人有所帮助。我花了 4 个小时试图解决这个问题。

    亚伦

    【讨论】:

    • 你说的是power-shell。我的 power-shell 版本没有那个“-Version”标志。它是:“安装包 Microsoft.TypeScript.MsBuild -RequiredVersion 3.5.3”。但我最终只是去包管理器寻求解决方案,搜索 typescript 并选择特定版本 3.5.3。我现在可以建造了。谢谢。
    【解决方案3】:

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

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

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

    【讨论】:

    • 谢谢。最后,我选择在 ng 项目和 .net core 项目之间划分我的工作。所以我收到了更快的构建以及分散的问题
    【解决方案4】:

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

    【讨论】:

      【解决方案5】:

      我猜它显示错误是因为您在某处尝试重新初始化同一属性两次或更多次。

      例如:

      let name = "John";
      let person = {
          name,
          name: "Jane"
      }
      

      如上面的代码,

      • 我们首先将该人的财产(姓名)分配给 John。
      • 但随后我们将该人的财产(姓名)重新分配给了 Jane。

      这将使第一次初始化变得多余。

      结果:person = {name: "Jane"}

      【讨论】:

        猜你喜欢
        • 2018-11-09
        • 2016-12-27
        • 2019-12-11
        • 2020-06-20
        • 2016-06-13
        • 2016-05-23
        • 2019-11-02
        • 2017-04-13
        • 2016-10-29
        相关资源
        最近更新 更多