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

error: Error: spawnSync git ENOBUFS #166

Closed
brunolemos opened this issue Aug 30, 2019 · 26 comments · Fixed by #287
Closed

error: Error: spawnSync git ENOBUFS #166

brunolemos opened this issue Aug 30, 2019 · 26 comments · Fixed by #287

Comments

@brunolemos
Copy link

Small reproduction:

  1. Create an empty folder with only one file: package.json

    {
      "name": "rw",
      "dependencies": {
        "react-window": "1.8.5"
      }
    }
  2. Make some changes inside node_modules/react-window/dist files

  3. npx patch-package react-window

  4. If fails with error below:

[17:05:40] brunolemos:rw $ patch-package react-window
patch-package 6.1.2
• Creating temporary folder
• Installing [email protected] with yarn
• Diffing your files with clean files

{
  error: Error: spawnSync git ENOBUFS
      at Object.spawnSync (internal/child_process.js:1041:20)
      at Object.spawnSync (child_process.js:607:24)
      at Function.spawnSync [as sync] (/usr/local/lib/node_modules/patch-package/node_modules/cross-spawn/index.js:26:23)
      at Object.exports.spawnSafeSync (/usr/local/lib/node_modules/patch-package/dist/spawnSafe.js:10:32)
      at git (/usr/local/lib/node_modules/patch-package/dist/makePatch.js:73:32)
      at Object.makePatch (/usr/local/lib/node_modules/patch-package/dist/makePatch.js:104:26)
      at /usr/local/lib/node_modules/patch-package/dist/index.js:48:25
      at Array.forEach (<anonymous>)
      at Object.<anonymous> (/usr/local/lib/node_modules/patch-package/dist/index.js:47:22)
      at Module._compile (internal/modules/cjs/loader.js:868:30) {
    errno: 'ENOBUFS',
    code: 'ENOBUFS',
    syscall: 'spawnSync git',
    path: 'git',
    spawnargs: [
      'diff',
      '--cached',
      '--no-color',
      '--ignore-space-at-eol',
      '--no-ext-diff'
    ]
  },
  status: null,
  signal: 'SIGTERM',
  output: [
    null,
    <Buffer 64 69 66 66 20 2d 2d 67 69 74 20 61 2f 6e 6f 64 65 5f 6d 6f 64 75 6c 65 73 2f 72 65 61 63 74 2d 77 69 6e 64 6f 77 2f 64 69 73 74 2f 69 6e 64 65 78 2d ... 1056718 more bytes>,
    <Buffer >
  ],
  pid: 79859,
  stdout: <Buffer 64 69 66 66 20 2d 2d 67 69 74 20 61 2f 6e 6f 64 65 5f 6d 6f 64 75 6c 65 73 2f 72 65 61 63 74 2d 77 69 6e 64 6f 77 2f 64 69 73 74 2f 69 6e 64 65 78 2d ... 1056718 more bytes>,
  stderr: <Buffer >
}

/usr/local/lib/node_modules/patch-package/dist/makePatch.js:150
        throw e;
        ^
{
  error: Error: spawnSync git ENOBUFS
      at Object.spawnSync (internal/child_process.js:1041:20)
      at Object.spawnSync (child_process.js:607:24)
      at Function.spawnSync [as sync] (/usr/local/lib/node_modules/patch-package/node_modules/cross-spawn/index.js:26:23)
      at Object.exports.spawnSafeSync (/usr/local/lib/node_modules/patch-package/dist/spawnSafe.js:10:32)
      at git (/usr/local/lib/node_modules/patch-package/dist/makePatch.js:73:32)
      at Object.makePatch (/usr/local/lib/node_modules/patch-package/dist/makePatch.js:104:26)
      at /usr/local/lib/node_modules/patch-package/dist/index.js:48:25
      at Array.forEach (<anonymous>)
      at Object.<anonymous> (/usr/local/lib/node_modules/patch-package/dist/index.js:47:22)
      at Module._compile (internal/modules/cjs/loader.js:868:30) {
    errno: 'ENOBUFS',
    code: 'ENOBUFS',
    syscall: 'spawnSync git',
    path: 'git',
    spawnargs: [
      'diff',
      '--cached',
      '--no-color',
      '--ignore-space-at-eol',
      '--no-ext-diff'
    ]
  },
  status: null,
  signal: 'SIGTERM',
  output: [
    null,
    <Buffer 64 69 66 66 20 2d 2d 67 69 74 20 61 2f 6e 6f 64 65 5f 6d 6f 64 75 6c 65 73 2f 72 65 61 63 74 2d 77 69 6e 64 6f 77 2f 64 69 73 74 2f 69 6e 64 65 78 2d ... 1056718 more bytes>,
    <Buffer >
  ],
  pid: 79859,
  stdout: <Buffer 64 69 66 66 20 2d 2d 67 69 74 20 61 2f 6e 6f 64 65 5f 6d 6f 64 75 6c 65 73 2f 72 65 61 63 74 2d 77 69 6e 64 6f 77 2f 64 69 73 74 2f 69 6e 64 65 78 2d ... 1056718 more bytes>,
  stderr: <Buffer >
}
[17:05:44] brunolemos:rw $ 
@brunolemos
Copy link
Author

This only happens when I was trying to patch the .js.map files as well. Maybe they are too big.

@pvinis
Copy link
Contributor

pvinis commented Dec 3, 2019

I don't think this should be closed. It would be cool to have a way to ignore these files.

@ldco2016
Copy link

ldco2016 commented Dec 4, 2019

@brunolemos , why was this closed? I get the same error when I tried to patch [email protected]

I ran npx patch-package react-native-immediate-phone-call and I got:

* Creating temporary folder
* Installing [email protected] with npm
* Diffing your files with clean files

{
  error: Error: spawnSync git ENOBUFS

@brunolemos brunolemos reopened this Dec 4, 2019
@marcus-sa
Copy link

marcus-sa commented Dec 13, 2019

Happens to me as well, and the file being added only contains a few bytes.

@alepri51
Copy link

i've the same problem
any workaround?

@SudoPlz
Copy link

SudoPlz commented Feb 27, 2020

@alepri51 I temporarily worked around it and managed to create my patch by going to:

⁨node_modules⁩/patch-package⁩/dist⁩/makePatch.js line 108, specifically in this code:

return spawnSafe_1.spawnSafeSync("git", args, {
                cwd: tmpRepo.name,
                env: { HOME: tmpRepo.name },
            });

and added an extra option called maxBuffer to increase the buffer size to 100mb (it was 1 mb by default which is too low)

now the code looks like this:

return spawnSafe_1.spawnSafeSync("git", args, {
                cwd: tmpRepo.name,
                env: { HOME: tmpRepo.name },
                maxBuffer: 1024 * 1024 * 100
            });

and my patch was created successfully.
I hope that helps someone.

@curio77
Copy link

curio77 commented Mar 8, 2020

Thank you, this helped. So we now need to patch-package patch-package? ;-)

@SudoPlz
Copy link

SudoPlz commented Mar 8, 2020

Hahaha yep

@leejh3224
Copy link

This seems to be in a high priority

@brussee
Copy link

brussee commented Apr 8, 2020

@alepri51 I temporarily worked around it and managed to create my patch by going to:

⁨node_modules⁩/patch-package⁩/dist⁩/makePatch.js line 108, specifically in this code:

return spawnSafe_1.spawnSafeSync("git", args, {
                cwd: tmpRepo.name,
                env: { HOME: tmpRepo.name },
            });

and added an extra option called maxBuffer to increase the buffer size to 100mb (it was 1 mb by default which is too low)

now the code looks like this:

return spawnSafe_1.spawnSafeSync("git", args, {
                cwd: tmpRepo.name,
                env: { HOME: tmpRepo.name },
                maxBuffer: 1024 * 1024 * 100
            });

and my patch was created successfully.
I hope that helps someone.

Here is a gist with the patch by @SudoPlz I'm using successfully:

https://gist.github.com/brussee/e382ed12ca007a88170289e54b526063

@Timebutt
Copy link

Can we get this fixed, possibly by upping the default maxBuffer or throwing a more clear error suggesting to up the maxBuffer when running the command?

I just ran into this too, and while it is incredibly meta to have to patch patch-package, it's not exactly the point ;)

@bjacog
Copy link

bjacog commented Jun 14, 2020

@Timebutt would it not be better to allow passing a maxBuffer param? There is a discussion of the same kind of problem in the Lerna repo here: lerna/lerna#479

It would also be nice to know what the buffer defaults to.

This issue comes up quite often when patching react-native packages for older repos as they could have some post-install steps which generate a large number of files.

@NathanBWaters
Copy link

Hit this when trying to patch the three node_module.
maxBuffer: 1024 * 1024 * 100 fixed it, thanks!

@alpharder
Copy link

So we basically need to patch the patch-package first in order to use it to patch other packages...

@KrzysztofMadejski
Copy link

Run into the same issue.

Artificially raising the maxBuffer seems to me a bit too much. I'd vote for cleaner message ("File too big: . Please raise --maxBuffer to over ") and option to change maxBuffer and optionally make it automatically adjust (check size of all files, if they are bigger than buffer than raise the bar before spawning git diff).

@sbrighiu
Copy link

sbrighiu commented Feb 16, 2021

To be honest if we raise maxBuffer to 2 mb it may fix everyone's issue ... just saying ..

@ds300 ds300 closed this as completed in #287 Mar 4, 2021
@ds300
Copy link
Owner

ds300 commented Mar 4, 2021

A fix for this was just released in v6.4.5. Thanks to @nomi9995 for making the PR 🙏🏼

@sbrighiu
Copy link

sbrighiu commented Mar 4, 2021

It seems too much for me, but it would fix the issue :)

In my case I was patching react native packages and when patching i had the build folder from android (build artifacts) included in the patch.. and that raised the current issue.

Simply removing that and being more mindful of the things actually added in the patch, would be my recommended way of handling situations like this.

Ashoat added a commit to CommE2E/comm that referenced this issue May 3, 2021
Summary: Fixes [this issue](ds300/patch-package#166)

Test Plan:
1. Make sure `patch-package react-native` works without needing to manually patch `patch-package`
2. Make sure `yarn cleaninstall` works and still patches correctly

Reviewers: palys-swm

Subscribers: KatPo, Adrian, atul

Differential Revision: https://phabricator.ashoat.com/D1086
@hirbod
Copy link

hirbod commented Dec 20, 2021

Still failing for me with 6.4.7

@numandev1
Copy link
Contributor

numandev1 commented Dec 21, 2021

@madeeha96
Copy link

My patch-package version is 6.4.7 and maxBuffer: 1024 * 1024 * 100 already added in the makePatch file. I still get this error

@madeeha96
Copy link

Got it fixed by increasing maxBuffer to maxBuffer: 2048 * 1024 * 100

@KrisLau
Copy link

KrisLau commented Aug 8, 2022

Happened for me with expo-modules-core with trying to apply the changes from this commit: expo/expo#18518

@ArnabSwiggy
Copy link

Got it fixed by increasing maxBuffer to maxBuffer: 2048 * 1024 * 100

That adds more issue, do check the diff file manually. If 1024 * 1024 * 100 is not working, means the diff is getting too large. Is it intentional? For me, it was no. Some random file diffs got added. Had to cleanup the diff manually.

@YesSkyscrapers
Copy link

YesSkyscrapers commented Jul 31, 2023

Update lib helped me ;D
was "patch-package": "^6.5.1",
now "patch-package": "^8.0.0",

@iArchin
Copy link

iArchin commented Nov 6, 2023

I also have the same problem with the version 8.0.0

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment