错误 TS2300:node_modules/@types/core-js/index.d.ts 中的标识符“PropertyKey”重复

Posted

技术标签:

【中文标题】错误 TS2300:node_modules/@types/core-js/index.d.ts 中的标识符“PropertyKey”重复【英文标题】:error TS2300: Duplicate identifier 'PropertyKey' in node_modules/@types/core-js/index.d.ts 【发布时间】:2017-04-13 02:39:18 【问题描述】:

我在 Visual Studio Code IDE 的 node_modules/@types/core-js/index.d.ts 中有这些错误:

当我运行 npm start 为应用程序提供服务时,我得到:

    node_modules/@types/core-js/index.d.ts(21,14): error TS2300: Duplicate identifier 'PropertyKey'.
node_modules/@types/core-js/index.d.ts(85,5): error TS2687: All declarations of 'name' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(145,5): error TS2403: 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'.
node_modules/@types/core-js/index.d.ts(262,5): error TS2687: All declarations of 'flags' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(276,5): error TS2687: All declarations of 'EPSILON' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(311,5): error TS2687: All declarations of 'MAX_SAFE_INTEGER' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(318,5): error TS2687: All declarations of 'MIN_SAFE_INTEGER' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(457,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"Symbol"', but here has type 'string'.
node_modules/@types/core-js/index.d.ts(457,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(464,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(492,5): error TS2687: All declarations of 'hasInstance' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(498,5): error TS2687: All declarations of 'isConcatSpreadable' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(504,5): error TS2687: All declarations of 'iterator' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(510,5): error TS2687: All declarations of 'match' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(516,5): error TS2687: All declarations of 'replace' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(522,5): error TS2687: All declarations of 'search' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(528,5): error TS2687: All declarations of 'species' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(534,5): error TS2687: All declarations of 'split' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(540,5): error TS2687: All declarations of 'toPrimitive' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(546,5): error TS2687: All declarations of 'toStringTag' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(552,5): error TS2687: All declarations of 'unscopables' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(609,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"Math"', but here has type 'string'.
node_modules/@types/core-js/index.d.ts(609,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(613,5): error TS2403: Subsequent variable declarations must have the same type.  Variable '[Symbol.toStringTag]' must be of type '"JSON"', but here has type 'string'.
node_modules/@types/core-js/index.d.ts(613,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(628,5): error TS2687: All declarations of 'size' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(634,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(645,5): error TS2687: All declarations of 'size' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(651,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(666,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(680,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(692,5): error TS2687: All declarations of 'value' must have identical modifiers.
node_modules/@types/core-js/index.d.ts(804,5): error TS2687: All declarations of 'prototype' must have identical modifiers.
node_modules/typescript/lib/lib.es2015.core.d.ts(17,14): error TS2300: Duplicate identifier 'PropertyKey'.

这是我的 tsconfig.json:

    
  "compilerOptions": 
    "target": "es5",
    "module": "system",
    "moduleResolution": "node",
    "lib": ["es2015", "dom"],
    "sourceMap": true,
    "emitDecoratorMetadata": true,
    "experimentalDecorators": true,
    "removeComments": false,
    "noImplicitAny": true,
    "outDir":"js/app/",
    "typeRoots": [
      "./node_modules/@types"
    ]
  ,
    "exclude": [
    "node_modules",
    "app/test"
  ]

我的 package.json

    
  "name": "vepo",
  "version": "1.0.0",
  "scripts": 
    "coverage": "istanbul cover ./test.js",
    "lite-server-test": "lite-server --config=liteserver-test-config.json",
    "test": "karma start karma.config.js",
    "start": "tsc && concurrently \"npm run tsc:w\" \"npm run lite\" \"sass --watch app\" \"sass --watch index.scss\" \"sass --watch global-constants.scss\" ",
    "lite": "lite-server",
    "tsc": "tsc",
    "tsc:w": "tsc -w"
  ,
  "bin":
    "e2e-test-start": "bin/e2e-test-start.js" 
,
  "license": "ISC",
  "moduleResolution": "node",
  "dependencies": 
    "@angular/common": "~2.2.0",
    "@angular/compiler": "~2.2.0",
    "@angular/core": "~2.2.0",
    "@angular/forms": "~2.2.0",
    "@angular/http": "~2.2.0",
    "@angular/platform-browser": "~2.2.0",
    "@angular/platform-browser-dynamic": "~2.2.0",
    "@angular/router": "~3.2.0",
    "@angular/upgrade": "~2.2.0",
    "@types/bootstrap": "^3.3.32",
    "@types/core-js": "^0.9.34",
    "@types/google-maps": "^3.1.28",
    "@types/jasmine": "^2.5.38",
    "@types/jquery": "^2.0.34",
    "@types/node": "^6.0.51",
    "angular-in-memory-web-api": "~0.1.15",
    "angular2-google-maps": "^0.15.0",
    "angular2-modal": "^2.0.0",
    "bootstrap": "^3.3.7",
    "core-js": "^2.4.1",
    "jquery": "v3.1.1",
    "jshint": "^2.9.4",
    "ng2-bs3-modal": "^0.10.4",
    "ng2-popover": "0.0.9",
    "protractor": "4.0.11",
    "reflect-metadata": "^0.1.8",
    "rxjs": "5.0.0-beta.12",
    "systemjs": "0.19.39",
    "tslint": "^4.0.2",
    "zone.js": "^0.6.25"
  ,
  "devDependencies": 
    "@types/google-maps": "^3.1.28",
    "angular-mocks": "^1.5.8",
    "codelyzer": "1.0.0-beta.0",
    "concurrently": "^3.0.0",
    "core-js": "^2.4.1",
    "del": "latest",
    "gulp": "^3.9.1",
    "gulp-changed": "^1.3.2",
    "gulp-concat": "^2.6.1",
    "gulp-imagemin": "^3.1.1",
    "gulp-jshint": "^2.0.4",
    "gulp-minify-html": "^1.0.6",
    "gulp-sass": "latest",
    "gulp-sourcemaps": "latest",
    "gulp-strip-debug": "^1.1.0",
    "gulp-tslint": "latest",
    "gulp-typescript": "latest",
    "gulp-uglify": "^2.0.0",
    "istanbul": "^0.4.5",
    "jasmine": "~2.4.1",
    "karma": "latest",
    "karma-chrome-launcher": "latest",
    "karma-cli": "^1.0.1",
    "karma-coverage": "latest",
    "karma-htmlfile-reporter": "^0.3.4",
    "karma-jasmine": "latest",
    "karma-jasmine-html-reporter": "^0.2.2",
    "karma-mocha-reporter": "latest",
    "karma-phantomjs2-launcher": "latest",
    "karma-story-reporter": "latest",
    "lite-server": "latest",
    "path": "latest",
    "phantomjs2": "latest",
    "protractor-jasmine2-html-reporter": "0.0.6",
    "require-dir": "latest",
    "systemjs-builder": "latest",
    "tslint": "latest",
    "typescript": "latest"
  

我该如何解决这个问题?

**编辑:我曾经将typings 用于.d.ts 文件,但我转向@types。我还更新了我的 npm 和节点以尝试解决此问题:

 app: '1.0.0',
  npm: '3.10.8',
  ares: '1.10.1-DEV',
  http_parser: '2.7.0',
  icu: '57.1',
  modules: '48',
  node: '5.something',
  openssl: '1.0.2j',
  uv: '1.9.1',
  v8: '5.1.281.84',
  zlib: '1.2.8' 

到这里:

 app: '1.0.0',
  npm: '4.0.2',
  ares: '1.10.1-DEV',
  http_parser: '2.7.0',
  icu: '57.1',
  modules: '48',
  node: '6.9.1',
  openssl: '1.0.2j',
  uv: '1.9.1',
  v8: '5.1.281.84',
  zlib: '1.2.8' 

npm-debug.log:

0 info it worked if it ends with ok
1 verbose cli [ '/usr/local/bin/node', '/usr/local/bin/npm', 'start' ]
2 info using npm@4.0.2
3 info using node@v6.9.1
4 verbose run-script [ 'prestart', 'start', 'poststart' ]
5 info lifecycle vepo@1.0.0~prestart: vepo@1.0.0
6 silly lifecycle vepo@1.0.0~prestart: no script for prestart, continuing
7 info lifecycle vepo@1.0.0~start: vepo@1.0.0
8 verbose lifecycle vepo@1.0.0~start: unsafe-perm in lifecycle true
9 verbose lifecycle vepo@1.0.0~start: PATH: /usr/local/lib/node_modules/npm/bin/node-gyp-bin:/Users/Ben/Development/vepo/node_modules/.bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
10 verbose lifecycle vepo@1.0.0~start: CWD: /Users/Ben/Development/vepo
11 silly lifecycle vepo@1.0.0~start: Args: [ '-c',
11 silly lifecycle   'tsc && concurrently "npm run tsc:w" "npm run lite" "sass --watch app" "sass --watch index.scss" "sass --watch global-constants.scss" ' ]
12 silly lifecycle vepo@1.0.0~start: Returned: code: 2  signal: null
13 info lifecycle vepo@1.0.0~start: Failed to exec start script
14 verbose stack Error: vepo@1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" "sass --watch app" "sass --watch index.scss" "sass --watch global-constants.scss" `
14 verbose stack Exit status 2
14 verbose stack     at EventEmitter.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/lifecycle.js:279:16)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at EventEmitter.emit (events.js:191:7)
14 verbose stack     at ChildProcess.<anonymous> (/usr/local/lib/node_modules/npm/lib/utils/spawn.js:40:14)
14 verbose stack     at emitTwo (events.js:106:13)
14 verbose stack     at ChildProcess.emit (events.js:191:7)
14 verbose stack     at maybeClose (internal/child_process.js:877:16)
14 verbose stack     at Process.ChildProcess._handle.onexit (internal/child_process.js:226:5)
15 verbose pkgid vepo@1.0.0
16 verbose cwd /Users/Ben/Development/vepo
17 error Darwin 16.1.0
18 error argv "/usr/local/bin/node" "/usr/local/bin/npm" "start"
19 error node v6.9.1
20 error npm  v4.0.2
21 error code ELIFECYCLE
22 error vepo@1.0.0 start: `tsc && concurrently "npm run tsc:w" "npm run lite" "sass --watch app" "sass --watch index.scss" "sass --watch global-constants.scss" `
22 error Exit status 2
23 error Failed at the vepo@1.0.0 start script 'tsc && concurrently "npm run tsc:w" "npm run lite" "sass --watch app" "sass --watch index.scss" "sass --watch global-constants.scss" '.
23 error Make sure you have the latest version of node.js and npm installed.
23 error If you do, this is most likely a problem with the vepo package,
23 error not with npm itself.
23 error Tell the author that this fails on your system:
23 error     tsc && concurrently "npm run tsc:w" "npm run lite" "sass --watch app" "sass --watch index.scss" "sass --watch global-constants.scss"
23 error You can get information on how to open an issue for this project with:
23 error     npm bugs vepo
23 error Or if that isn't available, you can get their info via:
23 error     npm owner ls vepo
23 error There is likely additional logging output above.
24 verbose exit [ 1, true ]

【问题讨论】:

尽量不包括那些 core-js 声明。 tsc 已经包含了它们,而且我认为 core-js 是旧的。查看这篇文章以了解类似的问题和解决方案 - ***.com/a/40802446/2038383。 @S.Pinkus 所以将“node_modules/@types/core-js”添加到excludestsconfig.json 字段?我已经试过了。还是您的意思是从@types 中删除core-js 文件夹? tsc 仍然可能会抓住它。它有一些非常奇怪的查找规则。尝试在 compilerOptions 中设置types: []。这是确保 tsc 不捡起它的最可靠方法。 @S.Pinkus 你让我走上了解决问题的道路。谢谢。 【参考方案1】:

"@types/core-js": "0.9.34" 升级到版本0.9.39 对我有用。

【讨论】:

这是真正的答案。删除 @types/core-js 将不起作用,因为 Angular 依赖于它,但升级到 0.9.39 会让它像梦一样工作! 首先我在打字稿中编辑:“@types/core-js”:“0.9.39”(甚至“^0.09.34”对我有用)。然后我在控制台中运行:npm install --save @types/core-js。谢谢!

以上是关于错误 TS2300:node_modules/@types/core-js/index.d.ts 中的标识符“PropertyKey”重复的主要内容,如果未能解决你的问题,请参考以下文章

错误 TS2300:重复标识符“RequestInfo”

TS2300:重复标识符“路由器”

错误 TS2300:node_modules/@types/core-js/index.d.ts 中的标识符“PropertyKey”重复

TS2300: Duplicate identifier问题的解决

错误 TS2339:“主页”类型上不存在属性“路由器”

两个不同 Angular 模型之间的映射