-
Notifications
You must be signed in to change notification settings - Fork 449
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug]: Cannot find module '@jest/globals' when cache: false #4245
Comments
It randomly happens even when cache property is not manually set: EnvWin 10 {
// package.json
"devDependencies": {
"@jest/globals": "29.1.1",
"jest": "29.1.1",
"ts-jest": "29.1.1",
"typescript": "^5.3.3"
},
"jest": {
"preset": "ts-jest/presets/default-esm",
"collectCoverage": true,
"coverageDirectory": "coverage",
"testEnvironment": "node",
"testMatch": [
"**/*.spec.ts"
],
"transform": {
"^.+\\.tsx?$": [
"ts-jest",
{ "diagnostics": { "ignoreCodes": [ "TS151001" ] } }
]
}
}
} // ts config
{
"compilerOptions": {
"module": "ESNext",
"noImplicitAny": true,
"sourceMap": true,
"baseUrl": ".",
"rootDir": ".",
"target": "ESNext",
"outDir": "./dist",
"skipLibCheck": true
},
"files": ["src/index.ts"]
} EditDid a bit more testing on my end and it seems to be an issue related to import v. require; If I require the globals the tests consistently pass without the afore mentioned error even when jest's // typed as any
const { describe, test, expect } = require('@jest/globals');
// ...tests ... If I use import I get the error the first time, but subsequent runs do not: import { describe, test, expect } from '@jest/globals';
// ...tests ... Maybe the caching mechanism is using |
Version
29.1.1
Steps to reproduce
I'm trying to setup ts-jest for ESM testing. While working through other jest weirdness, I found that setting their "cache" option to false prevents
@jest/globals
from being resolved.The zipped package minimally demonstrates this. Jest config is inline in package.json.
ts-jest-cache.zip
Expected behavior
The test should succeed regardless of the cache setting.
Actual behavior
npm run test
produces:Debug log
None was produced.
Additional context
I realize that this is a jest option, but it doesn't have this effect in a .js test.
Environment
The text was updated successfully, but these errors were encountered: