0

i followed this guide to use angular with .net mvc but i have no success. i tried the these solution below still cannot resolve the issue. I have the error in the file

TypeScript\node_modules\@types\core-js\index.d.ts

Solution

Here is the tsconfig and package.json both located in the root of the project.

  "dependencies": {
    "@angular/animations": "^5.0.0",
    "@angular/common": "^5.0.0",
    "@angular/compiler": "^5.0.0",
    "@angular/core": "^5.0.0",
    "@angular/forms": "^5.0.0",
    "@angular/http": "^5.0.0",
    "@angular/platform-browser": "^5.0.0",
    "@angular/platform-browser-dynamic": "^5.0.0",
    "@angular/router": "^5.0.0",
    "core-js": "^2.4.1",
    "rxjs": "^5.5.2",
    "zone.js": "^0.8.14",
    "typings": "^1.3.2"
  }

tsconfig

{
  "compileOnSave": false,
  "compilerOptions": {
    "outDir": "./dist/out-tsc",
    "sourceMap": true,
    "declaration": false,
    "moduleResolution": "node",
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "target": "es2017",
    "typeRoots": [
      "node_modules/@types"
    ],
    "lib": [
      "dom",
      "es2017"
    ]
  },
  "exclude": [
    "node_modules"
  ]
}
Alexei - check Codidact
  • 22,016
  • 16
  • 145
  • 164
Aatish Kumar
  • 149
  • 2
  • 15

1 Answers1

0

Do not depend on the @types/core-js package. It is almost entirely redundant with the official TypeScript declarations included explicitly by way of

"lib": ["dom", "es2017"]

Using

"target": "es2017"

Also implies the same but explicitly specifying --lib as you have done is in good practice.

By overlapping with the latest declarations for the DOM and ECMAScript APIs the @types/core-js package, which roughly describes the structure of the polyfills provided by the core-js package, introduces an extremely high likelihood that declarations will conflict . Furthermore, the @types/core-js package is far less well-maintained than the lib.es2017.d.ts declarations you are already referencing.

Since you have listed your dependencies, and @types/core-js is not among them, it is likely being installed transitively. Since it contains global declarations, this is inherently problematic.

To resolve the issue, set the "types" property explicitly in your tsconfig.json. This governs the inclusion of global @types packages by the TypeScript compiler.

Here is an example:

{
  "compilerOptions": {
    "types": [],

    "module": "esnext",
    "lib": ["dom", "es2017"]
  }
}

To include global @types declarations in such a setup, you must reference them in the newly added property.

Here is an example:

 {
  "compilerOptions": {
    "types": ["bootstrap", "mocha"],

    "module": "esnext",
    "lib": ["dom", "es2017"]
  }
}

Notes:

  1. Be sure to explicitly depend on any @types packages by installing them with your package manager. Relying on transitive dependencies will lead to non-deterministic builds, unpredictable CI failures, and general chaos.

  2. The @types/core-js package contains declarations for APIs that extend beyond the scope of ES2017. If you need access to these types, change the spec numbered value of --lib to esnext as in

    {
      "compilerOptions": {
        "lib": ["dom", "esnext"]
      }
    }
    
  3. You have a number of outdated and discrepant dependencies. In particular, "typings": "^1.3.2", is very old and should be updated. typings should also be installed as a development dependency, a feature supported by all package managers including typings itself.

Aluan Haddad
  • 29,886
  • 8
  • 72
  • 84