Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

VS2019 error TS2300: Duplicate identifier IteratorResult

I have an ASP.NET Core Project with Angular App inside it. After updating the project to .NET Core 3.0 release, I've got a problem. During ASP.NET Core Project build, I see 2 errors in the output:

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"
    ]
  }
}

What I tried:

  • update @type/node through npm;
  • delete @type/node from package.json;
  • change typescript (bottom of package.json) version to 3.6.4.
like image 375
Laser42 Avatar asked Oct 21 '19 11:10

Laser42


People also ask

How do I fix duplicate identifier?

To solve the "Duplicate identifier error":Make sure you don't have any clashing names of identifiers. Set the skipLibCheck option to true in your tsconfig. json file. Update the version of your typings, e.g. npm i -D @types/node@latest .

What is duplicate identifier issue in typescript?

Typescript allows duplicated identifier declarations in a single ts file, if duplicated identifiers have different declaration types. But it doesn't work to import identifiers from multiple files even though you know each imported identifiers have different declaration types.


3 Answers

I also had exactly the same problem with Vs2019 and angular version 8. I have tried as suggested above downloading and installing TypesScript compiler version 3.7 for VS2019. But the problem persisted.

The only way I solved the above problem as per J King's recommendation of upgrading node types higher than or equal to version 8.10.52. In then tsconfig.json file I have set the compiler target version to ES6. Then issued the following commands:

npm install @types/[email protected]

then do:

ng build

Make sure it builds cleanly. The do a clean build in Vs2019.

This seems to solve the problem.

like image 102
wkkhondkar Avatar answered Nov 19 '22 05:11

wkkhondkar


Angular 8 wants Typescript >= 3.4.0 and < 3.6.0, but Visual Studio 2019 builds using 3.7.

I was able to fix these issues by installing 3.5.3 in both NPM and Visual Studio.

npm install --save [email protected]

Install-Package Microsoft.TypeScript.MsBuild -Version 3.5.3

After that the Typescript version dropdown in project properties (TypeScript Build tab) is grayed out, but reads the correct value of 3.5 (NuGet). Saved, rebuilt and all was good.

Hope that helps someone. I spent 4 hours trying to fix this.

Aaron

like image 31
FunkMonkey33 Avatar answered Nov 19 '22 05:11

FunkMonkey33


I also got similar issue, but after installing Typescript on local machine from below link, http://www.typescriptlang.org/#download-links

I rebuild solution, it worked.

Note : Choose your appropriate VisualStudio version or any IDE you are using from download link!

like image 28
PavanT Avatar answered Nov 19 '22 06:11

PavanT