2016-06-27 52 views
1

我編譯所有打字稿在我的角度項目,但我得到了衆所周知的錯誤:錯誤TS2300:在打字稿重複的識別碼「需要」編譯過程

error TS2300: Duplicate identifier 'require'. 

但是誰擁有這個問題大多數人都跑成這是因爲他們有兩個文件導致重複錯誤。在我的情況下,這是因爲在相同的文件中使用了兩次使用「」字段需要

/typings/globals/angular/index.d.ts(1707,9): 

/typings/globals/angular/index.d.ts(1717,9): 

enter image description here

是從DT源被拉出的默認角度分型定義文件。

我有本地和全球的TypeScript。我試圖刪除本地副本,但錯誤了。這裏是我的tsconfig.json:

{ 
    "compilerOptions": { 
    "module": "commonjs", 
    "noImplicitAny": true, 
    "removeComments": true, 
    "preserveConstEnums": true, 
    "sourceMap": true 
    }, 
    "files": [ 
    "typings/index.d.ts" 
    ] 
} 

和我typings.json:

{ 
    "globalDependencies": { 
    "angular": "registry:dt/angular#1.5.0+20160627014139", 
    "bootstrap": "registry:dt/bootstrap#3.3.5+20160619023404", 
    "jquery": "registry:dt/jquery#1.10.0+20160620094458" 
    } 
} 

,最後我的主要index.d.ts:

/// <reference path="globals/angular/index.d.ts" /> 
/// <reference path="globals/bootstrap/index.d.ts" /> 
/// <reference path="globals/jquery/index.d.ts" /> 

回答

1

你不應該列出d.tstsconfig.json文件的files部分中的文件。那是你列出你寫的文件需要被轉換成javascript的地方。你看到的問題是由譯者試圖將你的typings/index.d.ts文件轉換爲JavaScript,它不應該這樣做。類型定義實際上只在那裏,以便您的代碼編輯器可以提供類型提示,警告錯誤並執行代碼完成。

看看this overview of the tsconfig.json file