Angular2重复标识符"PropertyKey" [英] Angular2 Duplicate identifier 'PropertyKey'

查看:74
本文介绍了Angular2重复标识符"PropertyKey"的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用angular-cli构建一个angular2应用程序.默认情况下未安装angular-in-memory-web-api.

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

所以我搜索了它,并将这行"angular-in-memory-web-api": "~0.1.5"添加到了我的package.json文件中.并做了npm install.

So I searched for it and added this line "angular-in-memory-web-api": "~0.1.5" in my package.json file. And did npm install.

此后,我出现此错误Cannot find type definition file for 'core-js' #90.我在 Github问题中找到了解决方法.

After this, I came with this error Cannot find type definition file for 'core-js' #90. I found a solution in this Github-question.

所以我按照github-question的建议运行了该命令npm install --save @types/core-js.现在,我遇到了这个错误.

So I ran this command npm install --save @types/core-js as suggested by github-question. Now I am facing this error.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:21:13 
Duplicate identifier 'PropertyKey'.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:85:4 
All declarations of 'name' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:145:4 
Subsequent variable declarations must have the same type.  Variable '[Symbol.unscopables]' must be of type '{ copyWithin: boolean; entries: boolean; fill: boolean; find: boolean; findIndex: boolean; keys: ...', but here has type 'any'.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:262:4 
All declarations of 'flags' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:276:4 
All declarations of 'EPSILON' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:311:4 
All declarations of 'MAX_SAFE_INTEGER' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:318:4 
All declarations of 'MIN_SAFE_INTEGER' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:457:4 
Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"Symbol"', but here has type 'string'.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:457:4 
All declarations of '[Symbol.toStringTag]' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:464:4 
All declarations of 'prototype' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:492:4 
All declarations of 'hasInstance' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:498:4 
All declarations of 'isConcatSpreadable' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:504:4 
All declarations of 'iterator' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:510:4 
All declarations of 'match' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:516:4 
All declarations of 'replace' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:522:4 
All declarations of 'search' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:528:4 
All declarations of 'species' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:534:4 
All declarations of 'split' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:540:4 
All declarations of 'toPrimitive' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:546:4 
All declarations of 'toStringTag' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:552:4 
All declarations of 'unscopables' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:609:4 
Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"Math"', but here has type 'string'.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:609:4 
All declarations of '[Symbol.toStringTag]' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:613:4 
Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"JSON"', but here has type 'string'.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:613:4 
All declarations of '[Symbol.toStringTag]' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:628:4 
All declarations of 'size' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:634:4 
All declarations of 'prototype' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:645:4 
All declarations of 'size' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:651:4 
All declarations of 'prototype' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:666:4 
All declarations of 'prototype' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:680:4 
All declarations of 'prototype' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:692:4 
All declarations of 'value' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/@types/core-js/index.d.ts:804:4 
All declarations of 'prototype' must have identical modifiers.

ERROR in [default] /home/adil/Code/AngularJS.2/cli-based/mz-doc-app/node_modules/typescript/lib/lib.es2015.core.d.ts:17:13 
Duplicate identifier 'PropertyKey'.

package.json

{
  "name": "mz-doc-app",
  "version": "0.0.0",
  "license": "MIT",
  "angular-cli": {},
  "scripts": {
    "start": "ng serve",
    "lint": "tslint \"src/**/*.ts\"",
    "test": "ng test",
    "pree2e": "webdriver-manager update",
    "e2e": "protractor"
  },
  "private": true,
  "dependencies": {
    "@angular/common": "~2.1.0",
    "@angular/compiler": "~2.1.0",
    "@angular/core": "~2.1.0",
    "@angular/forms": "~2.1.0",
    "@angular/http": "~2.1.0",
    "@angular/material": "^2.0.0-alpha.9-3",
    "@angular/platform-browser": "~2.1.0",
    "@angular/platform-browser-dynamic": "~2.1.0",
    "@angular/router": "~3.1.0",
    "@types/core-js": "^0.9.34",
    "angular-in-memory-web-api": "~0.1.5",
    "core-js": "^2.4.1",
    "rxjs": "5.0.0-beta.12",
    "ts-helpers": "^1.1.1",
    "zone.js": "^0.6.23"
  },
  "devDependencies": {
    "@types/jasmine": "^2.2.30",
    "@types/node": "^6.0.42",
    "angular-cli": "1.0.0-beta.18",
    "codelyzer": "1.0.0-beta.1",
    "jasmine-core": "2.4.1",
    "jasmine-spec-reporter": "2.5.0",
    "karma": "1.2.0",
    "karma-chrome-launcher": "^2.0.0",
    "karma-cli": "^1.0.1",
    "karma-jasmine": "^1.0.2",
    "karma-remap-istanbul": "^0.2.1",
    "protractor": "4.0.9",
    "ts-node": "1.2.1",
    "tslint": "3.13.0",
    "typescript": "~2.0.3"
  }
}

Result-of-tree-command

├── angular-cli.json
├── e2e
├── karma.conf.js
├── mz-doc-app.sublime-project
├── mz-doc-app.sublime-workspace
├── node_modules
├── package.json
├── protractor.conf.js
├── README.md
├── src
└── tslint.json

tsconfig.json

{
  "compileOnSave": false,
  "compilerOptions": {
    "declaration": false,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "module": "commonjs",
    "moduleResolution": "node",
    "outDir": "../dist/out-tsc-e2e",
    "sourceMap": true,
    "target": "es5",
    "typeRoots": [
      "../node_modules/@types"
    ]
  }, 
  "exclude":[
    "node_modules",
    "typings/main",
    "typings/main.d.ts"

  ]
}

请提出一些解决方案?

推荐答案

所以在将"target":"es5"升级到"target":"es6"时遇到了同样的问题 我通过升级tsconfig.json修复了该问题:

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

来自

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

收件人

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

博客文章很有帮助.

这是由相同类型定义的多个版本引起的.在 tsconfig.json我们将es6作为lib数组的一部分,但我们也有 node_modules/@ types中的core-js. core-js中的类型定义 与已经使用TypeScript分发的内容重叠.为了 要解决此问题,我们有两种选择:

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:

  • 在compilerOptions的lib属性中将es6更改为es5.这条路 TypeScript将不包含ES6类型定义.
  • 从中删除core-js node_modules.这样TypeScript将仅使用其内部ES6类型 定义.
  • 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.

这篇关于Angular2重复标识符"PropertyKey"的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆