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)

Commits related to this issue

Most upvoted comments

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',
  ],

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.

I finally managhed to fix this long lasting issue here’s the config that did the job

  transformIgnorePatterns: [
    '<rootDir>/node_modules/@babel',
    '<rootDir>/node_modules/@jest',
    '<rootDir>/node_modules/lodash',
    'signal-exit',
    'is-typedarray'
  ],

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

(node:26044) UnhandledPromiseRejectionWarning: TypeError: jest: failed to cache transform results in: /Users/Projects/system_acceptance_tests/.cache/jest-transform-cache-Assistant-SAT-afca7609b727bae58e6d966e4f38887d/1b/index_1bd26eb79e9d5f8a74d76de47d84899e.map
Failure message: onExit is not a function
    at writeFileSync (/Users/Projects/system_acceptance_tests/node_modules/write-file-atomic/index.js:201:31)
    at writeCacheFile (/Users/Projects/system_acceptance_tests/node_modules/@jest/transform/build/ScriptTransformer.js:791:33)
    at ScriptTransformer.transformSource (/Users/Projects/system_acceptance_tests/node_modules/@jest/transform/build/ScriptTransformer.js:536:7)
    at revertHook.exts (/Users/Projects/system_acceptance_tests/node_modules/@jest/transform/build/ScriptTransformer.js:655:18)
    at Module._compile (/Users/Projects/system_acceptance_tests/node_modules/pirates/lib/index.js:93:29)
    at Module._extensions..js (internal/modules/cjs/loader.js:1153:10)
    at Object.newLoader [as .js] (/Users/Projects/system_acceptance_tests/node_modules/pirates/lib/index.js:104:7)
    at Module.load (internal/modules/cjs/loader.js:977:32)
    at Function.Module._load (internal/modules/cjs/loader.js:877:14)
    at Module.require (internal/modules/cjs/loader.js:1019:19)
(node:26044) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). To terminate the node process on unhandled promise rejection, use the CLI flag `--unhandled-rejections=strict` (see https://nodejs.org/api/cli.html#cli_unhandled_rejections_mode). (rejection id: 2)
(node:26044) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.