我安装了NPM版的Typescript 1.7.5和angular2 beta。在Visual Studio 2015 Update 1中构建项目时,我收到此错误:
1>VSTSC : error TS2318: Build: Cannot find global type 'Iterable'.
1>VSTSC : error TS2318: Build: Cannot find global type 'IterableIterator'.
1>VSTSC : error TS2318: Build: Cannot find global type 'Symbol'.
1>VSTSC : error TS2468: Build: Cannot find global value 'Symbol'.
我的tsconfig.json文件是这样的:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": true,
"sourceMap": true,
"target": "es6",
"module": "system",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noLib": false
},
"exclude": [
"node_modules",
"wwwroot",
"bower_components"
],
"files": [
"node_modules/angular2/typings/tsd.d.ts",
"node_modules/angular2/typings/zone/zone.d.ts",
"node_modules/angular2/core.d.ts",
"node_modules/typescript/lib/lib.d.ts"
]
}
如何解决此错误?
更新:
我试过Martin Vseticka的回答。我收到以下错误:
1>C:\Test\node_modules\angular2\src\facade\lang.d.ts(2,22): error TS2304: Build: Cannot find name 'BrowserNodeGlobal'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(6,14): error TS2300: Build: Duplicate identifier 'PropertyKey'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(9,5): error TS2300: Build: Duplicate identifier 'done'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(10,5): error TS2300: Build: Duplicate identifier 'value'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(248,5): error TS2300: Build: Duplicate identifier 'EPSILON'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(283,5): error TS2300: Build: Duplicate identifier 'MAX_SAFE_INTEGER'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(290,5): error TS2300: Build: Duplicate identifier 'MIN_SAFE_INTEGER'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(346,5): error TS2300: Build: Duplicate identifier 'flags'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(498,5): error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(561,5): error TS2300: Build: Duplicate identifier 'size'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(570,5): error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(581,5): error TS2300: Build: Duplicate identifier 'size'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(590,5): error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(605,5): error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(619,5): error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(3841,14): error TS2300: Build: Duplicate identifier 'PropertyKey'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4061,5): error TS2300: Build: Duplicate identifier 'EPSILON'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4096,5): error TS2300: Build: Duplicate identifier 'MAX_SAFE_INTEGER'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4103,5): error TS2300: Build: Duplicate identifier 'MIN_SAFE_INTEGER'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4389,5): error TS2300: Build: Duplicate identifier 'done'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4390,5): error TS2300: Build: Duplicate identifier 'value'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4619,5): error TS2300: Build: Duplicate identifier 'flags'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4647,5): error TS2300: Build: Duplicate identifier 'size'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4657,5): error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4674,5): error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4686,5): error TS2300: Build: Duplicate identifier 'size'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4696,5): error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(4712,5): error TS2300: Build: Duplicate identifier 'prototype'.
1>C:\Program Files (x86)\Microsoft SDKs\TypeScript\1.7\lib.es6.d.ts(5099,5): error TS2300: Build: Duplicate identifier 'prototype'.
当我尝试David Sherrit的回答时,我得到了14175个错误。错误始于:
1>C:\Test\node_modules\angular2\src\facade\lang.d.ts(2,22): error TS2304: Build: Cannot find name 'BrowserNodeGlobal'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(6,14): error TS2300: Build: Duplicate identifier 'PropertyKey'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(9,5): error TS2300: Build: Duplicate identifier 'done'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(10,5): error TS2300: Build: Duplicate identifier 'value'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(248,5): error TS2300: Build: Duplicate identifier 'EPSILON'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(283,5): error TS2300: Build: Duplicate identifier 'MAX_SAFE_INTEGER'.
1>C:\Test\node_modules\angular2\typings\es6-shim\es6-shim.d.ts(290,5): error TS2300: Build: Duplicate identifier 'MIN_SAFE_INTEGER'.
更新:
我试过了:
{
"compilerOptions": {
"noImplicitAny": false,
"noEmitOnError": true,
"removeComments": true,
"sourceMap": true,
"target": "es6",
"module": "system",
"emitDecoratorMetadata": true,
"experimentalDecorators": true,
"noLib": false
},
"exclude": [
"node_modules",
"wwwroot",
"bower_components"
],
"files": [
"node_modules/angular2/core.d.ts",
"node_modules/typescript/lib/lib.d.ts",
"node_modules/typescript/lib/lib.es6.d.ts"
]
}
但仍然会出现大约14162个错误,主要是重复错误。将 noLib 转换为 true 没有帮助。
答案 0 :(得分:1)
您似乎添加了lib.d.ts
两次,因为您使用了noLib
而且您在node_modules/typescript/lib/lib.d.ts
中专门添加了files
。
我只想删除"node_modules/typescript/lib/lib.d.ts"
路径。
还有类似错误的问题:https://github.com/Microsoft/TypeScript/issues/5504
答案 1 :(得分:1)
通常当noLib
设置为true
且target
设置为es6
时,除了lib.es6.d.ts
之外,它还会包含lib.d.ts
。 lib.es6.d.ts
包含特定于ES6的定义。
但是,您要包含lib.d.ts
,该语句位于该文件的顶部:
/// <reference no-default-lib="true"/>
这会覆盖您的tsconfig.json
选项,并将noLib
设置为true
;因此,它不包括lib.es6.d.ts
。这解释了您的错误。
如果您想继续使用node_modules/typescript/...
中的定义文件,则还需要包含lib.es6.d.ts
:
"files": [
"node_modules/angular2/typings/tsd.d.ts",
"node_modules/angular2/typings/zone/zone.d.ts",
"node_modules/angular2/core.d.ts",
"node_modules/typescript/lib/lib.d.ts",
"node_modules/typescript/lib/lib.es6.d.ts"
]
否则,请将noLib
保留为false
,并在文件列表中删除对lib.d.ts
的引用,以遵循Martin的回答。