Skip to content
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

Jest fails with EBADF: bad file descriptor, close #7709

Closed
hediet opened this issue Jan 25, 2019 · 41 comments · Fixed by #7725
Closed

Jest fails with EBADF: bad file descriptor, close #7709

hediet opened this issue Jan 25, 2019 · 41 comments · Fixed by #7725
Labels

Comments

@hediet
Copy link

hediet commented Jan 25, 2019

🐛 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
@SimenB
Copy link
Member

SimenB commented Jan 25, 2019

What version of jest and what version of node?

@hediet
Copy link
Author

hediet commented Jan 25, 2019

PS C:\Users\Henning\Workspace\reactmain> yarn run jest --version
yarn run v1.10.1
$ C:\Users\Henning\Workspace\reactmain\node_modules\.bin\jest --version
24.0.0
Done in 0.34s.
PS C:\Users\Henning\Workspace\reactmain> node --version
v10.11.0

@SimenB
Copy link
Member

SimenB commented Jan 25, 2019

@rubennorte does RN support another jest than the bundled version?

@bookman25
Copy link
Contributor

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

@SimenB
Copy link
Member

SimenB commented Jan 25, 2019

With RN or plain Jest?

@bookman25
Copy link
Contributor

bookman25 commented Jan 25, 2019

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: [...],
}

@SimenB
Copy link
Member

SimenB commented Jan 26, 2019

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: npm/write-file-atomic@v2.3.0...v2.4.2

@steven-pribilinskiy
Copy link

Occurring with me too. Fails when >100 tests are run in a single run.
With this blocker Jest cannot be used along with some precommit hook on Windows

@SimenB
Copy link
Member

SimenB commented Jan 27, 2019

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

@steven-pribilinskiy
Copy link

I have

    "jest": {
      "version": "23.6.0",
    "write-file-atomic": {
      "version": "2.3.0",

checked both in package-lock.json and in package.json-s in node_modules

@steven-pribilinskiy
Copy link

btw, there's no string match for write-file-atomic in node_modules/jest

@SimenB
Copy link
Member

SimenB commented Jan 27, 2019

It's part of jest-runtime. Easiest is to run npm ls write-file-atomic and see what it spits out

But if you're on Jest 23 (and on write-file-atomic@2.3.0), it's not the same issue (I think).

@steven-pribilinskiy
Copy link

I see, well jest-runtime uses write-file-atomic directly from node_modules/.
What else can trigger this error

@SimenB
Copy link
Member

SimenB commented Jan 27, 2019

It's not the same as we're seeing on our own CI, or the user above here

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

In your case, I'd follow #4444

@lukeapage
Copy link
Contributor

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.

clarkdo added a commit to nuxt/nuxt that referenced this issue Jan 28, 2019
turn on runInBand before jestjs/jest#7709 gets solved
@s-bauer
Copy link

s-bauer commented Jan 30, 2019

@SimenB Any info when a new version with this fix will be released?

@SimenB
Copy link
Member

SimenB commented Jan 30, 2019

hopefully today

@blackholegalaxy
Copy link

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?

@SimenB
Copy link
Member

SimenB commented Jan 30, 2019

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

@kluplau
Copy link

kluplau commented Jan 31, 2019

We encountered this issue today as well. Did you manage to fix this yesterday?

@justinhp
Copy link

justinhp commented Jan 31, 2019

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" },

@KevinTCoughlin
Copy link

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

Thank you, this was helpful 😄!

@nadavsinai
Copy link

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

@nickhow83
Copy link

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

@SimenB
Copy link
Member

SimenB commented Feb 5, 2019

24.1.0 is out: 8a2ea1e

@nasreddineskandrani
Copy link
Contributor

i get

npm ERR! code ETARGET
npm ERR! notarget No matching version found for jest@24.1.0

@SimenB
Copy link
Member

SimenB commented Feb 5, 2019

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

@nickhow83
Copy link

Yep. Definitely there. I’ll make use of this tomorrow. Thank you

@SimenB
Copy link
Member

SimenB commented Feb 19, 2019

You linked to this very issue

@mscottx88
Copy link

The write-file-atomic resolution strategy does not appear to work with yarn workspaces 👎

@SimenB
Copy link
Member

SimenB commented Mar 11, 2019

Resolutions doesn't matter here, jest has locked down the dependency. If you've got issues, please open up a new issue with reproduction steps

@mscottx88
Copy link

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.

@CMarshall92
Copy link

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

@tscislo
Copy link

tscislo commented May 22, 2019

Any chance this fix to be merged to 23?

@thymikee
Copy link
Collaborator

thymikee commented May 22, 2019

@tscislo not likely, we don't maintain past versions, only the current one. There would be too much maintenance burden and we just don't have enough people do deal with it.

What's holding you back from upgrading to v24?

@tscislo
Copy link

tscislo commented May 22, 2019

@thymikee well we need to migrate sooner or later, but having a fix for 23 would allow us to keep it for some time now.
Especially as the fix on Jest side is easy you just need to change dependency in package.json in
jest-runtime from "write-file-atomic": "^2.1.0", to "write-file-atomic": "=2.4.1"

@thymikee
Copy link
Collaborator

fix on Jest side is easy

Well, it isn't as easy as you'd think. We need a FB employee to release a version, which may be hard to arrange at times. Feel free to ping @scotthovestadt and maybe he'll do something about it :).

@thymikee
Copy link
Collaborator

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 🙂

@sebastianpatten
Copy link

In case it helps anyone - I had forgotten to npm install and received this message. Installing fixed it for me.

@connorjayfitzgerald
Copy link

We have a project using Yarn workspaces, with 5 TypeScript packages. Jest and ts-jest installed at the root.
Tests ran ok locally but kept getting this error in our pipeline. Can confirm that adding

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

to our package.json got around the issue.

"@types/jest": "25.1.4",
"jest": "25.2.3",
"ts-jest": "25.2.1",

@github-actions
Copy link

This issue has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs.
Please note this issue tracker is not a help forum. We recommend using StackOverflow or our discord channel for questions.

@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 11, 2021
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging a pull request may close this issue.