jest: Jest fails with EBADF: bad file descriptor, close

šŸ› Bug Report

Jests fails multiple times with:

jest: failed to cache transform results in: C:/Users/Henning/AppData/Local/Temp/jest/jest-transform-cache-21ff455c7f0bd09e66d08b5df7fc2a40-e2c4083dbe718f612529eff10eba50fe/e3/error-guard_e3806b360161eb5615267fc2e1997a27
    Failure message: EBADF: bad file descriptor, close

at Object.closeSync (node_modules/graceful-fs/graceful-fs.js:52:27)

To Reproduce

Run react-native init, copy the file App.js in __Tests__ several times (more than 10 times). Run yarn test.

Expected behavior

All tests pass.

Run npx envinfo --preset jest

  System:
    OS: Windows 10
    CPU: (12) x64 Intel(R) Core(TM) i7-8750H CPU @ 2.20GHz
  Binaries:
    Yarn: 1.10.1 - C:\Program Files (x86)\Yarn\bin\yarn.CMD
    npm: 6.4.1 - C:\Program Files\nodejs\npm.CMD

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 12
  • Comments: 41 (17 by maintainers)

Commits related to this issue

Most upvoted comments

I can confirm 23.6.0 is affected too and was fixed by using npm resolutions

and

  "resolutions": {
    "write-file-atomic": "2.4.1"
  }

in package.json

this was happening with jest 23.6 for my team as well. I went ahead and added "write-file-atomic": "2.4.1" to resolutions in my package.json: "resolutions": { "write-file-atomic": "2.4.1" },

Feels a bit dirty using resolutionsā€¦ do we know when a 24.0.1 or 24.1 will be out?

Thatā€™s an issue either with your network or a proxy/registry of some kind. Itā€™s definitely available:

https://www.npmjs.com/package/jest image

Could the fix be also applied to 23.x versions?

No, not unless absolutely necessary. And we have donā€™t really have a fix. The ā€œfixā€ is to rollback write-file-atomic, which you can do yourself with a lockfile or yarnā€™s resolutions. 2.4.2 is the one with the error, so use 2.3.0 (what jest 23 came with) or 2.4.0/2.4.1

Same problem once upgrading to jest 24, windows 10. Iā€™ve downgraded write-file-atomic to 2.4.1 with manual copying of an old version and it stopped having errors. re installing and the error comes back. i cleared my cache before each test.

Related to #4444 (last few comments there), seems like something in the upgrade from write-file-atomic 2.3.0 -> 2.4.2 broke something.

Can you try to either manually edit node_modules/write-file-atomic/index.js or use yarn resolutions to force 2.3.0 and see if that fixes your error?

Diff: https://github.com/npm/write-file-atomic/compare/v2.3.0...v2.4.2

I encountered this problem today on our large scale project. We use locked 23.6.0 jest version. Could the fix be also applied to 23.x versions?

Iā€™m also seeing this error after upgrading. Was previously using jest@23.6 successfully. Post upgrade getting this cache error randomly.

Oh, and btw, if you use Yarn, feel free to use the "resolutions" field in package.json to get this done, or use the patch-package project šŸ™‚

I encountered this problem today on our large scale project. We use locked 23.6.0 jest version. Could the fix be also applied to 23.x versions?

22.4 also has this issue

Thatā€™s great, just letting the next google-fu-master that finds this thread to avoid trying the workaround if they might be using yarn workspaces.

Iā€™ve opened up #7725. @pribilinskiy it would be awesome if you could test by installing write-file-atomic@2.4.1 (jest comes with 2.4.2) locally and see if it fixes your issue. Either uses resolutions if you use yarn, or manually replacing in node_modules

Plain jest.

abbreviated jest.config.js

{
	automock: true,
	cacheDirectory: '<rootDir>/.jest-cache',
	clearMocks: true,
	collectCoverageFrom: [...],
	coverageReporters: ['text-summary', 'html', 'clover'],
	coverageThreshold: {
		global: {
			statements: 85,
			branches: 80,
			functions: 72,
			lines: 85,
		},
	},
	moduleFileExtensions: ['tsx', 'ts', 'js', 'json'],
	moduleNameMapper: {
		'cv/(.*)': '<rootDir>/node_modules/content-viewer/dist/commonjs/$1',
	},
	setupTestFrameworkScriptFile: '<rootDir>/jestEnvironment.js',
	testEnvironment: 'node',
	testPathIgnorePatterns: ['_Auth', 'IntegrationSpec'],
	testRegex: 'Spec.tsx?$',
	timers: 'fake',
	transform: {
		'\\.(ts|tsx)$': '<rootDir>/src/testHelpers/transformTS.js',
		'\\.(css|svg|gif|png|jpg|jpeg)$': '<rootDir>/src/testHelpers/transformResource.js',
	},
	unmockedModulePathPatterns: [...],
}