2016-10-25 43 views
3

我正在升級使用Typtro 2.0與量角器4.0.5。我正在從typcript 1.8和量角器3.8升級一個項目。我來翻過了一堆的問題,我在這裏分享:量角器與Typescript 2.0.0重複標識問題

我的package.json是:

{ 
"dependencies": { 
"core-js": "2.2.2", 
"rxjs": "5.0.0-beta.6", 
"web-request": "^1.0.3", 
"zone.js": "0.6.12" 
}, 
"devDependencies": { 
"@types/jasmine": "^2.5.35", 
"@types/node": "^6.0.45", 
"@types/protractor": "^1.5.20", 
"@types/selenium-webdriver": "^2.53.33", 
"es6-promise": "3.1.2", 
"es6-promise-loader": "1.0.1", 
"es6-shim": "0.35.0", 
"es7-reflect-metadata": "1.6.0", 
"exports-loader": "0.6.3", 
"imports-loader": "0.6.5", 
"jasmine-reporters": "^2.2.0", 
"json-loader": "0.5.4", 
"mkdirp": "^0.5.1", 
"phantomjs-polyfill": "0.0.2", 
"phantomjs-prebuilt": "2.1.7", 
"pix-diff": "^1.0.14", 
"protractor": "4.0.5", 
"protractor-jasmine2-html-reporter": "0.0.6", 
"protractor-jasmine2-screenshot-reporter": "^0.3.2", 
"raw-loader": "0.5.1", 
"rimraf": "2.5.2", 
"ts-helpers": "1.1.1", 
"ts-node": "0.7.1", 
"tslint": "3.7.4", 
"tslint-loader": "2.1.3", 
"typedoc": "0.4.3", 
"typescript": "^2.0.0-beta", 
"underscore": "^1.8.3" 
} 

然後我的包JSON是:

"compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "sourceMap": true, 
    "noEmitHelpers": true, 
    "lib": ["es6", "dom"], 
    "types":[ 
    ] 
    }, 
    "exclude": [ 
    "node_modules", 
    "typings" 
    ], 
    "filesGlob": [ 
    "./src/**/*.ts", 
    "!./node_modules/**/*.ts" 
    ], 
    "awesomeTypescriptLoaderOptions": { 
    "resolveGlobs": true, 
    "forkChecker": true, 
    "compiler": "node_modules/typescript" 
    }, 
    "compileOnSave": false, 
    "buildOnSave": false, 
    "atom": { "rewriteTsconfig": false } 
} 

當我嘗試運行量角器使用該設置進行測試,我得到一堆這樣的錯誤:

node_modules\@types\selenium-webdriver\index.d.ts (12,11): Duplicate identifier 'Driver'. (2300) 
node_modules\@types\selenium-webdriver\index.d.ts (46,11): Duplicate identifier 'Options'. (2300) 
node_modules\@types\selenium-webdriver\index.d.ts (310,11): Duplicate identifier 'ServiceBuilder'. (2300) 
node_modules\protractor\typings\globals\selenium-webdriver\index.d.ts (12,11): Duplicate identifier 'Driver'. (2300) 
node_modules\protractor\typings\globals\selenium-webdriver\index.d.ts (46,11): Duplicate identifier 'Options'. (2300) 
node_modules\protractor\typings\globals\selenium-webdriver\index.d.ts (310,11): Duplicate identifier 'ServiceBuilder'. (2300) 

如何解決該問題,因爲我貝爾一切都安裝正確。我正在使用Protractor 4.0.5,它應該與typescript 2.0一起工作。

+0

你能添加一個最小的'* .ts'文件,導致它可能是有用的問題?我對量角器一無所知,但這似乎是類型定義的一個問題,所以我可以嘗試提供幫助。 –

+0

@HuyNguyen好的。我將在今天晚些時候添加示例存儲庫。 –

回答

0

請在protractor處打開問題。它不應該在其包裝中部署類型selenium-webdriver

現在,試試這個醜陋的黑客,看它是否解決了問題:

// tsconfig.json 
{ 
    "exclude": [ 
    "node_modules/protractor/typings/global/selenium-webdriver" 
    ] 
} 
2

量角器取出類型聲明中的版本5.x版本,那麼你可以簡單地升級量角器你的版本」重新使用,問題應該消失。

如果你有/想留在4.0.5版本中,你可以隨時卸載webdriver的類型,通過運行:

npm uninstall --save-dev @types/selenium-webdriver 
0

嘗試使用這樣的事情。我修改typeRootsexclude

{ 
"compilerOptions": { 
    "target": "es5", 
    "module": "commonjs", 
    "emitDecoratorMetadata": true, 
    "experimentalDecorators": true, 
    "sourceMap": true, 
    "noEmitHelpers": true, 
    "lib": ["es6", "dom"], 
    "types":[ 
    ], 
    "typeRoots": [ 
     "node_modules/@types" 
    ] 
    }, 
    "exclude": [ 
    "node_modules", 
    "node_modules/protractor/node_modules" 
    ], 
    "filesGlob": [ 
    "./src/**/*.ts", 
    "!./node_modules/**/*.ts" 
    ], 
    "awesomeTypescriptLoaderOptions": { 
    "resolveGlobs": true, 
    "forkChecker": true, 
    "compiler": "node_modules/typescript" 
    }, 
    "compileOnSave": false, 
    "buildOnSave": false, 
    "atom": { "rewriteTsconfig": false } 
} 

我創建了一個模板與打字稿2配置量角器:https://github.com/suvroc/protractor-typescript-template