jest: failed to cache transform results

See original GitHub issue

🐛 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.

Issue Analytics

  • State:closed
  • Created 4 years ago
  • Reactions:14
  • Comments:17 (1 by maintainers)

github_iconTop GitHub Comments

7reactions
ascott18commented, Oct 14, 2020

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 that require('signal-exit') is assigned to in write-file-atomic.

Combined with @dobesv 's ignores for jest and babel themselves:

  transformIgnorePatterns: [
    '<rootDir>/node_modules/@babel',
    '<rootDir>/node_modules/@jest',
    'signal-exit',
  ],
4reactions
dobesvcommented, May 6, 2020

I tried this to my jest config and it seems to fix it:

  transformIgnorePatterns: [
    '<rootDir>/node_modules/@babel',
    '<rootDir>/node_modules/@jest',
  ],

I guess jest is transforming itself somehow and this is causing the issue.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Jest fails all the time due to "Failed to cache transform results ...
Most of my calls to jest.runCLI (I run jest from a gulpfile) end up with the following error: jest: failed to cache transform...
Read more >
Fix Jest's "failed to cache transform results in..EPERM
Fix Jest's "failed to cache transform results in..EPERM: operation not permitted" on Windows. jest, node, windows.
Read more >
How can I clear the Jest cache? - Stack Overflow
You can find the cache location by running jest --showConfig . Look for the cacheDirectory key.
Read more >
Troubleshooting - Jest
Retry with --no-cache . Jest caches transformed module files to speed up test execution. If you are using your own custom transformer, consider ......
Read more >
A brand new website interface for an even better experience!
Jest fails all the time due to "Failed to cache transform results" on Windows.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found