我使用webdriverio mocha框架与typescript。@wdio/cli":"^ 7.25.0"NodeJs v16.13.2NPM V8.1.2中
我在tsconfig.json
JSON schema for the TypeScript compiler's configuration file
Cannot find type definition file for '@wdio/globals/types'.
The file is in the program because:
Entry point of type library '@wdio/globals/types' specified in compilerOptions
Mytsconfig.json
{
"compilerOptions":
{
"moduleResolution": "node",
"module": "CommonJS",
"types":
[
"node",
"@wdio/globals/types",
"expect-webdriverio",
"@wdio/mocha-framework",
],
"lib":
[
"dom",
"es7"
],
"target": "es2022"
}
}
Mypackage.json
{
"name": "mocha-template",
"version": "1.0.0",
"description": "",
"main": "index.js",
"keywords": [],
"author": "",
"license": "ISC",
"scripts":
{
"WDIO": "npx wdio run ./test/config/wdio.web.conf.ts"
},
"dependencies": {
"@types/node": "^18.8.3",
"@wdio/cli": "^7.25.0",
"@wdio/junit-reporter": "^7.25.1",
"@wdio/local-runner": "^7.25.1",
"@wdio/mocha-framework": "^7.25.1",
"@wdio/sauce-service": "^7.25.1",
"@wdio/spec-reporter": "^7.25.1",
"chai": "^4.3.6",
"chai-http": "^4.3.0",
"chromedriver": "^108.0.0",
"deepmerge": "^4.2.2",
"dotenv": "^16.0.3",
"eslint": "^8.25.0",
"eslint-plugin-mocha": "^10.1.0",
"eslint-plugin-prettier": "^4.2.1",
"fs-extra": "^10.1.0",
"moment": "^2.29.4",
"prettier": "^2.7.1",
"ts-node": "^10.9.1",
"typescript": "^4.8.4",
"wdio-chromedriver-service": "^8.0.0",
"wdio-video-reporter": "^3.2.3"
}
}
我可以运行我的测试,但这个错误更烦人。如果我打开任何测试文件意味着它显示browser
和$
的错误如何解决以上问题
For$
Cannot find name '$'. Do you need to install type definitions for jQuery? Try `npm i --save-dev @types/jquery` and then add 'jquery' to the types field in your tsconfig.
browser
Cannot find name 'browser'.
建议将根据您使用的WebDriverIO版本而更改(如果您在版本7中使用同步模式或异步模式)。以下是版本7和版本8的设置:
Version 7将相关代码片段添加到tsconfig.json
中。Version 7 docs here
异步
{
"compilerOptions": {
"types": ["node", "webdriverio/async"]
}
}
{
"compilerOptions": {
"types": ["node", "webdriverio/sync"]
}
}
Version 8
将这段代码添加到您的tsconfig: Version 8文档中
{
"compilerOptions": {
"types": ["node", "@wdio/globals/types"]
}
}
所以你遇到麻烦的原因可能是因为你试图将版本8的类型导入到你的webdriver版本7项目中。
没有@wdio/globals/types
类型,您只需从同步或异步包中使用一个。https://v7.webdriver.io/docs/typescript/框架安装
{
"compilerOptions": {
"types": ["node", "webdriverio/async"]
}
}