具有Typescript 2.0.0的量角器重复标识符问题

时间:2016-10-25 10:44:34

标签: selenium-webdriver typescript npm protractor typescript2.0

我正在升级以使用带有Protractor 4.0.5的Typescript 2.0。我正在从typescript 1.8和量角器3.8升级项目。我遇到了很多问题,我在这里分享:

我的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。

3 个答案:

答案 0 :(得分:2)

Protractor删除了5.x版本中的类型声明,因此您只需升级您正在使用的Protractor版本,问题就会消失。

如果您/想要继续使用4.0.5版,则可以通过运行以下命令来卸载webdriver类型:

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

答案 1 :(得分:0)

请在protractor处打开一个问题。它不应在其包中部署selenium-webdriver的类型。

现在,尝试这个丑陋的黑客,看它是否可以解决问题:

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

答案 2 :(得分:0)

尝试使用这样的东西。我修改了@RequestBody typeRoots

exclude

我创建了一个模板,用于使用TypeScript 2配置Protractor:https://github.com/suvroc/protractor-typescript-template

它可能对您有用