2016-10-31 17 views
5

Tôi đang xây dựng một ứng dụng angular2 sử dụng angular-cli. angular-in-memory-web-api không được cài đặt theo mặc định.Angular2 Mã định danh trùng lặp 'PropertyKey'

Vì vậy, tôi đã tìm kiếm và thêm dòng này "angular-in-memory-web-api": "~0.1.5" vào tệp package.json của tôi. Và đã làm npm install.

Sau này, tôi đi kèm với lỗi này Cannot find type definition file for 'core-js' #90. Tôi đã tìm thấy giải pháp trong số Github-question này.

Vì vậy, tôi đã chạy lệnh này npm install --save @types/core-js theo đề xuất của github-question. Bây giờ tôi đang đối mặt với lỗi này.

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" 

    ] 
} 

Xin gợi ý một số giải pháp?

+0

Bạn có thư mục 'typings' với thư mục' nút' bên trong không? Tôi nghĩ rằng 'phụ thuộc' loại/nút' và 'nút' bên trong' typings' có thể gây ra vấn đề. (Từ kinh nghiệm quá khứ của tôi).Xóa một thư mục trong thư mục 'npm_modules' và mục nhập devDependencies (vì bạn có thể hoàn nguyên) và cho chúng tôi biết điều gì sẽ xảy ra. – Searching

Trả lời

0

Nó có vẻ như bạn đang biên soạn trong thư mục node_modules, vì vậy, trong tsconfig.json của bạn (mà tôi đoán bạn có) chắc chắn để thiết lập trừ của mình cho trình biên dịch bỏ qua:

{ 
    "compileOnSave": true, 
    "compilerOptions": { 
    <...> 
    }, 
    "exclude": [ 
    "node_modules" 
    ] 
} 
2

Vì vậy, tôi chạy vào vấn đề này tương tự khi nâng cấp "target":"es5" để "target":"es6" tôi cố định nó bằng cách nâng cấp tsconfig.json tôi:

Từ

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

blog article này đã giúp ích rất nhiều.

Điều này là do nhiều phiên bản của cùng định nghĩa loại. Trong tsconfig.json, chúng tôi có es6 như một phần của mảng lib nhưng chúng tôi cũng có các mã số lõi trong các nút node_modules/@. Các định nghĩa kiểu trong lõi-js trùng lặp với các định nghĩa đã được phân phối với TypeScript. Để khắc phục sự cố này, chúng tôi có hai tùy chọn:

  • Thay đổi es6 thành es5 trong thuộc tính lib của tài sản. Bằng cách này, TypeScript sẽ không bao gồm định nghĩa kiểu ES6.
  • Xóa lõi-js khỏi nút_modules. Bằng cách này, TypeScript sẽ chỉ sử dụng các định nghĩa kiểu nội bộ của ES6 là .
Các vấn đề liên quan