2017-07-20 59 views
0

工作,我從我的gruntfile.js中執行以下任務咕嚕:typescriptUsingTsConfig沒有在我的項目

'typescriptUsingTsConfig': { 
     'basic': { 
      'options': { 
       'rootDir': './ng2' 
      } 
     } 
    } 

我複製從任務成功運行的另一個項目此任務。當我運行這個任務,我得到

在這篇文章的底部的錯誤。打印版本2.4.0是爲這個項目安裝的。我是

不知道這裏缺少什麼。

============================================== ================================================== ====

C:\CODE\Test\src\Test.Website> cmd.exe /c grunt -b "C:\CODE\Test\src\Test.Website" --gruntfile "C: 

\CODE\Test\src\Test.Website\Gruntfile.js" typescriptUsingTsConfig --color 
Running "typescriptUsingTsConfig:basic" (typescriptUsingTsConfig) task 
Running C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Web\External\Node.exe C: 

\CODE\Test\src\Test.Website\node_modules\typescript\bin\tsc --project ./ng2 
Warning: ng2/app.module.ts(1,21): error TS6053: File 

'C:/CODE/Test/src/Test.Website/typings/globals/core-js/index.d.ts' not found. 
ng2/services/user.service.ts(37,16): error TS2693: 'Promise' only refers to a type, but is being used 

as a value here. 
node_modules/@angular/common/src/directives/ng_class.d.ts(48,34): error TS2304: Cannot find name 

'Set'. 
node_modules/@angular/compiler/src/aot/compiler.d.ts(56,32): error TS2304: Cannot find name 'Map'. 
node_modules/@angular/compiler/src/compile_metadata.d.ts(369,20): error TS2304: Cannot find name 

'Set'. 
node_modules/@angular/compiler/src/compile_metadata.d.ts(371,28): error TS2304: Cannot find name 

'Set'. 
node_modules/@angular/compiler/src/compile_metadata.d.ts(373,15): error TS2304: Cannot find name 

'Set'. 
node_modules/@angular/compiler/src/compile_metadata.d.ts(375,23): error TS2304: Cannot find name 

'Set'. 
node_modules/@angular/compiler/src/compile_metadata.d.ts(377,17): error TS2304: Cannot find name 

'Set'. 
node_modules/@angular/compiler/src/compile_metadata.d.ts(379,25): error TS2304: Cannot find name 

'Set'. 
node_modules/@angular/compiler/src/output/output_ast.d.ts(458,63): error TS2304: Cannot find name 

'Set'. 
node_modules/@angular/core/src/change_detection/differs/default_iterable_differ.d.ts(28,32): error 

TS2304: Cannot find name 'Iterable'. 
node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(24,16): error 

TS2304: Cannot find name 'Map'. 
node_modules/@angular/core/src/change_detection/differs/default_keyvalue_differ.d.ts(32,16): error 

TS2304: Cannot find name 'Map'. 
node_modules/@angular/core/src/change_detection/differs/iterable_differs.d.ts(15,48): error TS2304: 

Cannot find name 'Iterable'. 
node_modules/@angular/core/src/change_detection/differs/keyvalue_differs.d.ts(23,18): error TS2304: 

Cannot find name 'Map'. 
node_modules/@angular/core/src/di/reflective_provider.d.ts(87,123): error TS2304: Cannot find name 

'Map'. 
node_modules/@angular/core/src/di/reflective_provider.d.ts(87,165): error TS2304: Cannot find name 

'Map'. 
node_modules/@angular/http/src/headers.d.ts(52,71): error TS2304: Cannot find name 'Map'. 
node_modules/@angular/http/src/url_search_params.d.ts(46,16): error TS2304: Cannot find name 'Map'. 
node_modules/@angular/platform-browser/src/browser/browser_adapter.d.ts(79,33): error TS2304: Cannot 

find name 'Map'. 
node_modules/@angular/platform-browser/src/dom/dom_adapter.d.ts(97,42): error TS2304: Cannot find name 

'Map'. 
node_modules/@angular/platform-browser/src/dom/shared_styles_host.d.ts(11,30): error TS2304: Cannot 

find name 'Set'. 
node_modules/@angular/platform-browser/src/dom/shared_styles_host.d.ts(22,30): error TS2304: Cannot 

find name 'Set'. 
node_modules/@angular/router/src/router_outlet_context.d.ts(42,28): error TS2304: Cannot find name 

'Map'. 
node_modules/@angular/router/src/router_outlet_context.d.ts(43,34): error TS2304: Cannot find name 

'Map'. 
node_modules/rxjs/Observable.d.ts(68,60): error TS2693: 'Promise' only refers to a type, but is being 

used as a value here. 
node_modules/rxjs/Subject.d.ts(16,22): error TS2415: Class 'Subject<T>' incorrectly extends base class 

'Observable<T>'. 
    Types of property 'lift' are incompatible. 
    Type '<R>(operator: Operator<T, R>) => Observable<T>' is not assignable to type '<R>(operator: 

Operator<T, R>) => Observable<R>'. 
     Type 'Observable<T>' is not assignable to type 'Observable<R>'. 
     Type 'T' is not assignable to type 'R'. 
node_modules/rxjs/operator/toPromise.d.ts(3,79): error TS2693: 'Promise' only refers to a type, but is 

being used as a value here. Use --force to continue. 
Aborted due to warnings. 
Process terminated with code 1. 

UPDATE

我更新了我的設置根據反饋到這個線程,但現在收到以下錯誤:

C:\CODE\Test.Web.Benport\src\Test.Web.Website> cmd.exe /c grunt -b "C:\CODE\Test.Web.Benport\src\Test.Web.Website" --gruntfile "C:\CODE\Test.Web.Benport\src\Test.Web.Website\Gruntfile.js" typescriptUsingTsConfig --color 
Running "typescriptUsingTsConfig:basic" (typescriptUsingTsConfig) task 
Running C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Web\External\Node.exe C:\CODE\Test.Web.Benport\src\Test.Web.Website\node_modules\typescript\bin\tsc --project ./ng2 
Warning: node_modules/typescript/lib/lib.es2015.collection.d.ts(45,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters. 
node_modules/typescript/lib/lib.es2015.core.d.ts(21,14): error TS2300: Duplicate identifier 'PropertyKey'. 
node_modules/typescript/lib/lib.es2015.iterable.d.ts(124,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters. 
node_modules/typescript/lib/lib.es2015.symbol.wellknown.d.ts(133,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters. 
typings/globals/core-js/index.d.ts(3,14): error TS2300: Duplicate identifier 'PropertyKey'. 
typings/globals/core-js/index.d.ts(67,5): error TS2687: All declarations of 'name' must have identical modifiers. 
typings/globals/core-js/index.d.ts(127,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'. 
typings/globals/core-js/index.d.ts(244,5): error TS2687: All declarations of 'flags' must have identical modifiers. 
typings/globals/core-js/index.d.ts(258,5): error TS2687: All declarations of 'EPSILON' must have identical modifiers. 
typings/globals/core-js/index.d.ts(293,5): error TS2687: All declarations of 'MAX_SAFE_INTEGER' must have identical modifiers. 
typings/globals/core-js/index.d.ts(300,5): error TS2687: All declarations of 'MIN_SAFE_INTEGER' must have identical modifiers. 
typings/globals/core-js/index.d.ts(439,5): error TS2403: Subsequent variable declarations must have the same type. Variable '[Symbol.toStringTag]' must be of type '"Symbol"', but here has type 'string'. 
typings/globals/core-js/index.d.ts(439,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers. 
typings/globals/core-js/index.d.ts(446,5): error TS2687: All declarations of 'prototype' must have identical modifiers. 
typings/globals/core-js/index.d.ts(474,5): error TS2687: All declarations of 'hasInstance' must have identical modifiers. 
typings/globals/core-js/index.d.ts(480,5): error TS2687: All declarations of 'isConcatSpreadable' must have identical modifiers. 
typings/globals/core-js/index.d.ts(486,5): error TS2687: All declarations of 'iterator' must have identical modifiers. 
typings/globals/core-js/index.d.ts(492,5): error TS2687: All declarations of 'match' must have identical modifiers. 
typings/globals/core-js/index.d.ts(498,5): error TS2687: All declarations of 'replace' must have identical modifiers. 
typings/globals/core-js/index.d.ts(504,5): error TS2687: All declarations of 'search' must have identical modifiers. 
typings/globals/core-js/index.d.ts(510,5): error TS2687: All declarations of 'species' must have identical modifiers. 
typings/globals/core-js/index.d.ts(516,5): error TS2687: All declarations of 'split' must have identical modifiers. 
typings/globals/core-js/index.d.ts(522,5): error TS2687: All declarations of 'toPrimitive' must have identical modifiers. 
typings/globals/core-js/index.d.ts(528,5): error TS2687: All declarations of 'toStringTag' must have identical modifiers. 
typings/globals/core-js/index.d.ts(534,5): error TS2687: All declarations of 'unscopables' must have identical modifiers. 
typings/globals/core-js/index.d.ts(591,5): error TS2403: Subsequent variable declarations must have the same type. Variable '[Symbol.toStringTag]' must be of type '"Math"', but here has type 'string'. 
typings/globals/core-js/index.d.ts(591,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers. 
typings/globals/core-js/index.d.ts(595,5): error TS2403: Subsequent variable declarations must have the same type. Variable '[Symbol.toStringTag]' must be of type '"JSON"', but here has type 'string'. 
typings/globals/core-js/index.d.ts(595,5): error TS2687: All declarations of '[Symbol.toStringTag]' must have identical modifiers. 
typings/globals/core-js/index.d.ts(610,5): error TS2687: All declarations of 'size' must have identical modifiers. 
typings/globals/core-js/index.d.ts(616,5): error TS2687: All declarations of 'prototype' must have identical modifiers. 
typings/globals/core-js/index.d.ts(627,5): error TS2687: All declarations of 'size' must have identical modifiers. 
typings/globals/core-js/index.d.ts(633,5): error TS2687: All declarations of 'prototype' must have identical modifiers. 
typings/globals/core-js/index.d.ts(638,11): error TS2428: All declarations of 'WeakMap' must have identical type parameters. 
typings/globals/core-js/index.d.ts(646,27): error TS2344: Type 'K' does not satisfy the constraint 'object'. 
typings/globals/core-js/index.d.ts(647,53): error TS2344: Type 'K' does not satisfy the constraint 'object'. 
typings/globals/core-js/index.d.ts(648,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'prototype' must be of type 'WeakMap<object, any>', but here has type 'WeakMap<any, any>'. 
typings/globals/core-js/index.d.ts(648,5): error TS2687: All declarations of 'prototype' must have identical modifiers. 
typings/globals/core-js/index.d.ts(662,5): error TS2403: Subsequent variable declarations must have the same type. Variable 'prototype' must be of type 'WeakSet<object>', but here has type 'WeakSet<any>'. 
typings/globals/core-js/index.d.ts(662,5): error TS2687: All declarations of 'prototype' must have identical modifiers. 
typings/globals/core-js/index.d.ts(674,5): error TS2687: All declarations of 'value' must have identical modifiers. 
typings/globals/core-js/index.d.ts(786,5): error TS2687: All declarations of 'prototype' must have identical modifiers. Use --force to continue. 
Aborted due to warnings. 
Process terminated with code 1. 

回答

0

確定這樣的錯誤正是這說:

'C:/CODE/Test/src/Test.Website/typings/globals/core-js/index.d.ts' not found. ng2/services/user.service.ts(37,16): error TS2693: 'Promise' only refers to a type, but is being used

聲明文件丟失。我不是類似Grunt的TypeScript配置,因爲我已經使用了3年左右,但這裏是我推薦的。

運行

typings uninstall --save core-js 

然後以防萬一運行

npm uninstall --save @types/core-js 

在tsconfig文件,更改

然後或`「compilerOptions」特性"lib"選項,

{ 
    "compilerOptions": { 
    "lib": ["dom", "es2015"], 
    // whatever else you had previously 
    } 
} 

最後如下設置,您可能需要以解決的最後一個錯誤添加the declaration I suggest in this answer(一對於rxjs /主題)

另外,如果你是好奇,爲什麼聲明核心JS會導致這些問題read my answer to a related question

+0

謝謝Aluan。我提出了你建議的更新,但我現在似乎正在得到一個新的錯誤。我用「UPDATE」標籤下的錯誤日誌更新了我的原始文章 – user8334943

+0

看起來您仍然有'core-js'的類型文件,即'typings/globals/core-js/index.d.ts'正在造成這些錯誤。刪除這個文件並確保它不再在'typings.json'清單中列出。 –

相關問題