Angular2 Duplicate identifier 'PropertyKey'

前端 未结 2 1826
眼角桃花
眼角桃花 2021-01-18 18:42

I am building an angular2 application using angular-cli. angular-in-memory-web-api was not installed by default.

So I searched

相关标签:
2条回答
  • 2021-01-18 19:00

    It seems like you are compiling in the node_modules folder, so, in your tsconfig.json (that I presume you have) make sure to set your exclusions for the compiler to ignore:

    {
      "compileOnSave": true,
      "compilerOptions": {
        <...>
      },
      "exclude": [
        "node_modules"
      ] 
    }
    
    0 讨论(0)
  • 2021-01-18 19:09

    So I ran into this same issue when upgrading "target":"es5" to "target":"es6" I fixed it by upgrading my tsconfig.json:

    From

    {
      "compilerOptions": {
        "target": "es6",
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
      }
    }
    

    To

    {
      "compilerOptions": {
        "target": "es6",
         "lib": ["dom", "es5"],
        "typeRoots": [
          "./node_modules/@types"
        ],
        "module": "commonjs",
        "moduleResolution": "node",
        "sourceMap": true,
        "emitDecoratorMetadata": true,
        "experimentalDecorators": true,
        "removeComments": false,
        "noImplicitAny": false
      },
      "exclude": [
        "node_modules",
        "dist"
      ],
      "compileOnSave": false
    }
    

    This blog article helped a lot.

    This is caused by multiple versions of the same type definitions. In tsconfig.json we have es6 as part of the lib array but we also have core-js in node_modules/@types. The type definitions in core-js overlap with the ones already distributed with TypeScript. In order to fix this problem we have two options:

    • Change es6 to es5 in compilerOptions’s lib property. This way TypeScript won’t include ES6 type definitions.
    • Remove core-js from node_modules. This way TypeScript will use only its internal ES6 type definitions.
    0 讨论(0)
提交回复
热议问题