TS 2307:找不到模块“@jest/globals”或其对应的类型声明

huwehgph  于 2023-08-01  发布在  Jest
关注(0)|答案(1)|浏览(240)

出现错误TS 2307:为我的默认测试套件导入值时找不到模块“@jest/globals”或其对应的类型声明(但成功通过

import { describe, expect, test } from '@jest/globals'

describe('Example test', () => {
    test('something', () => {
        expect('').toBeFalsy()
    })
})

字符串
我的package.json

"devDependencies": {
        "@types/jest": "^27.0.3",
        "@types/node": "^16.11.11",
        ...
        "typescript": "^4.4.4",
    },
    "optionalDependencies": {
        ...
    },
    "dependencies": {
        "@jest/globals": "^27.4.2",
        "babel-preset-jest": "^27.4.0",
        ...
    }
}


有人能帮我吗?

e37o9pze

e37o9pze1#

如果使用ts-jest,包版本应该与其他Jest库相同。
通过将@jest/globalsjestjest-environment-jsdom的版本降低到29.1.1ts-jest的最新版本),我的问题得到了解决:

"@jest/globals": "29.1.1",
    "jest": "29.1.1",
    "jest-environment-jsdom": "29.1.1",
    "ts-jest": "29.1.1"

字符串

相关问题