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

Fs-extra v8, copy function gives error when using with jest #687

Closed
vladshcherbin opened this issue May 15, 2019 · 20 comments
Closed

Fs-extra v8, copy function gives error when using with jest #687

vladshcherbin opened this issue May 15, 2019 · 20 comments
Labels

Comments

@vladshcherbin
Copy link

vladshcherbin commented May 15, 2019

  • Operating System: mac os 10.13.4
  • Node.js version: 12.1.0
  • fs-extra version: 8.0.1

Hey, 👋

After updating fs-extra from v7 to v8, jest tests started to give error for copy function:

TypeError: cb.apply is not a function

Screen Shot 2019-05-15 at 03 49 04

Here is same reproduction repo with failing test. The repo has only two commits, one is with v7 and no error, second is just an update to v8 and with error.

I saw this from travis, which gave error for node v10 and v12, but not for v8. Here is travis log. Rollback to v7 removes error.

Any idea why this is happening? 🤔

@MrXyfir
Copy link

MrXyfir commented May 15, 2019

Also getting this error. I haven't bothered to hunt down which function is causing it but in my case I'm not using copy().

@manidlou
Copy link
Collaborator

hmm..! That's so weird! That error basically comes from graceful-fs that we use as a dependency. But we disabled that and used native fs in fs-extra v8.0.1 to use fs.stat() with bigint option.

@manidlou
Copy link
Collaborator

wondering if we need to disable that in the fs/index.js until they update their code!

@RyanZim
Copy link
Collaborator

RyanZim commented May 15, 2019

Would be useful to have a non-jest example so we could get the full stack trace.

@vladshcherbin
Copy link
Author

@RyanZim I tried same example without jest (same node version 12.1.0) and it didn't give me error.

const fs = require('fs-extra')

async function run() {
  const src = 'tests/fixtures/src/asset.js'
  const dest = 'tests/fixtures/dist/asset.js'

  await fs.copy(src, dest)
}

run()

@vladshcherbin
Copy link
Author

vladshcherbin commented May 15, 2019

My best attempt to get error:

/Users/shcherbin/Sites/test/experiments/fs-extra-8-jest/node_modules/graceful-fs/polyfills.js:285
        if (cb) cb.apply(this, arguments)
                   ^

TypeError: cb.apply is not a function
    at /Users/shcherbin/Sites/test/experiments/fs-extra-8-jest/node_modules/graceful-fs/polyfills.js:285:20
    at FSReqCallback.oncomplete (fs.js:167:5)

@RyanZim
Copy link
Collaborator

RyanZim commented May 15, 2019

Jest globally monkey-patches the fs module itself: https://github.com/facebook/jest/blob/bcc2b103e14912cff566cbacb0c2c3871ecb0994/packages/jest-runtime/src/cli/index.ts#L26

See https://github.com/isaacs/node-graceful-fs#global-patching for details about this.

IDK how best to work with this. Should fs-extra try to detect global monkey patching and run without bigint?

@RyanZim
Copy link
Collaborator

RyanZim commented May 15, 2019

The root problem is that graceful-fs is broken and needs updates. Not sure how to get action there.

@manidlou
Copy link
Collaborator

Yeah exactly! If graceful-fs was updated we didn't go through all of this hassle!

@swernerx
Copy link

Anybody opened a bug/issue report on this one? Seems like more and more projects are crashing. Jest is used prettify massively right now.

swernerx added a commit to sebastian-software/rollup-plugin-rebase that referenced this issue Jun 20, 2019
@RyanZim
Copy link
Collaborator

RyanZim commented Jun 20, 2019

The root issue is isaacs/node-graceful-fs#158; if we could get action there, we'd be good.

@RyanZim
Copy link
Collaborator

RyanZim commented Jun 27, 2019

graceful-fs issue is fixed, I'm thinking this issue should be fixed by reinstalling/regenerating the lockfiles to get the latest graceful-fs. Let me know if it's not.

@RyanZim RyanZim closed this as completed Jun 27, 2019
@fastfrwrd
Copy link

fastfrwrd commented Jun 28, 2019

Hm, I still seem to see the error with 8.1.0. I used yarn ls to double check, it's pulling 4.2.0 through but it still throws this error when using fs.copy() in a Jest test.

TypeError: cb.apply is not a function

      at ../../../node_modules/graceful-fs/polyfills.js:285:20

@RyanZim
Copy link
Collaborator

RyanZim commented Jun 28, 2019

What version of graceful-fs is jest pulling in?

@fastfrwrd
Copy link

Per an npm ls, it's 4.2.0.

$ npm ls | grep graceful-fs
graceful-fs@4.2.0

@RyanZim
Copy link
Collaborator

RyanZim commented Jul 1, 2019

I'd like to see the output of npm ls graceful-fs.

@vladshcherbin
Copy link
Author

Just checked, the issue is fixed for me when using graceful-fs 4.2.0.

@fastfrwrd
Copy link

fastfrwrd commented Jul 2, 2019 via email

@RyanZim
Copy link
Collaborator

RyanZim commented Jul 2, 2019

@fastfrwrd Try doing a clean install/regenerating the lockfile.

@ondrej-kvasnovsky
Copy link

Yep, adding "graceful-fs": "4.2.2" library helped.

Repository owner locked as resolved and limited conversation to collaborators Aug 19, 2019
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

7 participants