jest: jest: failed to cache transform results
🐛 Bug Report
I’m using jest@25.1.0 on Mac with this config
module.exports = {
name: '',
verbose: true,
reporters: [
'default', [
],
testRunner: 'jest-circus/runner',
setupFilesAfterEnv: [
'expect-puppeteer',
'<rootDir>/setup.js'
],
preset: 'jest-puppeteer',
testEnvironment: 'jest-environment-puppeteer',
globalSetup: '<rootDir>/global-setup.js',
transform: {
'^.+\\.[t|j]sx?$': 'babel-jest'
},
transformIgnorePatterns: [
'/node_modules/(automation-framework)'
]
};
To Reproduce
When I run my tests, 1st time I got no errors but then systematically I got this error :
TypeError: jest: failed to cache transform results in: /private/var/folders/cd/9gmr40cd7gvg_4bjdlzdcvtm0000gn/T/jest_dx/jest-transform-cache-test-xxx-663cd5096d102708621094a35b6499ca/6f/index_6f50b55f88b774b3246293b72bc76e53.map
Failure message: onExit is not a function
at writeFileSync (/Users/.../node_modules/write-file-atomic/index.js:177:31)
at writeCacheFile (/Users/.../node_modules/@jest/transform/build/ScriptTransformer.js:739:33)
at ScriptTransformer.transformSource (/Users/.../node_modules/@jest/transform/build/ScriptTransformer.js:493:7)
at revertHook.exts (/Users/.../node_modules/@jest/transform/build/ScriptTransformer.js:601:23)
at Module._compile (/Users/.../node_modules/pirates/lib/index.js:93:29)
at Module._extensions..js (internal/modules/cjs/loader.js:995:10)
at Object.newLoader [as .js] (/Users/.../node_modules/pirates/lib/index.js:104:7)
at Module.load (internal/modules/cjs/loader.js:815:32)
at Function.Module._load (internal/modules/cjs/loader.js:727:14)
at Module.require (internal/modules/cjs/loader.js:852:19)`
I’ve read some similar old issues but none gave a clear way to fix this. Could someone help please? Thanks.
About this issue
- Original URL
- State: closed
- Created 4 years ago
- Reactions: 14
- Comments: 17 (2 by maintainers)
I managed to fix this by preventing babel transform of signal-exit. This package, used by a bunch of dependencies of jest itself, has a default function export which apparently gets mangled by babel into no longer being a function. This is why the error is “onExit is not a function” -
onExit
is the variable thatrequire('signal-exit')
is assigned to inwrite-file-atomic
.Combined with @dobesv 's ignores for jest and babel themselves:
I tried this to my jest config and it seems to fix it:
I guess jest is transforming itself somehow and this is causing the issue.
I finally managhed to fix this long lasting issue here’s the config that did the job
Big kudos to @ascott18 for opening my eyes on the source of this damn issue 😄 👏
with the update jest@26.0.1, I got the following error