bun
bun copied to clipboard
`bun patch` fails with EACCES Permission denied mkdir() when adding new files in nested directory
What version of Bun is running?
1.1.21+70ca2b76c
What platform is your computer?
Darwin 23.5.0 arm64 arm
What steps can reproduce the bug?
Add any package that has multiple levels of directories, this specific test is with the typescript package. Add a random file to any existing directory in the package that is two levels deep.
bun add typescript
bun patch typescript
# ADD a file in any directory that is child directory of typescript/lib, contents can be anything.
vim node_modules/typescript/lib/es/test.txt
bun patch --commit 'node_modules/typescript'
What is the expected behavior?
After running the bun patch --commit command there should be no error, and the file that was created (ie node_modules/typescript/lib/es/test.txt) should be in place.
What do you see instead?
Shell output is like this:
bun patch v1.1.21 (70ca2b76)
error: failed applying patch file: EACCES: lib/es: Permission denied (mkdir())
Checked 8 installs across 10 packages (no changes) [586.00ms]
error: failed to apply patchfile (patches/[email protected])
It did successfully edit the package.json file and it created this patch file:
diff --git a/node_modules/typescript/lib/es/test.txt b/lib/es/test.txt
new file mode 100644
index 0000000000000000000000000000000000000000..cca7f3bea8af2ec95ec0f2ca6331f9437d515919
--- /dev/null
+++ b/lib/es/test.txt
@@ -0,0 +1,2 @@
+This is in the lib/es dir
+
However, when it attempts to apply the patch file it fails. Repeated attempts to delete the package and run bun install result in the same error: failed applying patch file: EACCES: lib/es: Permission denied (mkdir()) error.
Additional information
When I try to add a file to the root of the package (ie, node_modules/typescript/) or to a subdirectory (ie, node_modules/typescript/lib) it seems to work just fine. This only seems to arise when the file is being added to a directory multiple levels deep. Note that editing files that are multiple levels deep works fine as well, it is only when creating a new file.
I've replicated this problem on a couple of different packages so far. My actual target package is called qbo and interestingly on that package I am able to add a file within the node_modules/qbo/src/entities/ dir, but I cannot add any files to the node_modules/qbo/dist/entities dir nor can I add to the node_modules/qbo/dist/lib dir.
A couple additional notes:
- I tried this same package edit with
pnpm patchand it worked without a problem. - I took the patch file that bun created and I and applied it "manually" with
patch -p1 < [email protected]and that worked without a problem.
Potentially Related: #12882
Using v1.1.25 on MacOS 14.5, I patched a few files in the dist/lib/builder folder of a package and then received an error when committing the patch:
error: failed applying patch file: EACCES: dist/lib/builder: Permission denied (mkdir())
It created the patch successfully. The error happens when trying to apply the patch. It seems to be doing something in the cwd. It added a dist folder in my top-level folder. Running ls on that folder gives an error:
% ls dist
ls: fts_read: Permission denied
It created the folder with 644 permissions instead of 755. If I chmod 755 dist and then run bun i again, it fails again with the same error. But now I have a dist/lib folder with 644 permissions. If I jump ahead and create all of the folders that were modified in the package in my project's top-level cwd with proper 755 permissions and run bun i, the patch is applied without error. I can then delete the dist folder and bun i continues to run without error due to having cached the patched package.
Interesting @rmarscher. I tried out your steps and replicated.
I guess a difference in your use case vs mine is that in my case the package already had a dist/some-dir directory and bun patch commit wouldn't let me create any files in that dir (although I could edit files in the same dir), and in your case the package didn't even have a dist directory to start with and weirdly bun patch commit tried to create directories within your project directory instead of in the package itself. Seems like these could be related but could be slightly different bugs I suppose?
Still seeing this on MacOS with bun version 1.1.27-canary.62
Also seeing this on 1.1.30
I'm seeing this also with bun v1.1.34. I'm attempting to migrate a large react-native monorepo from Yarn Classic to bun, and unfortunately, this is likely to be a blocker.
Running into this as well.
Our current workaround has been to patch patch-package so it doesn't use yarn.. though it would be desirable to not have to do this.
@Jarred-Sumner can we get this in 1.2?
seems like it's working since 1.2.1 for me try it out.
using bun 1.2.2 and still having the issue when i try to patch expo package like hirbod issue
Just happened to me on Bun 1.2.4, on both Arch Linux and macOS 15.1.1 attempting to patch @capacitor/push-notifications's ios/Sources/PushNotificationsPlugin/PushNotificationsHandler.swift
Any movement on this?
On macOS specifically, this error (EACCES: Permission denied (mkdir())) can also occur when the diff includes changes to the much-loathed .DS_Store file (which it will if you happened to open any of the relevant folders in Finder while making your edits). Removing the .DS_Store portion from the diff resolves the issue.
diff --git a/node_modules/next/dist/client/.DS_Store b/dist/client/.DS_Store
new file mode 100644
index 0000000000000000000000000000000000000000..dbd07c1a1c1d289c1b490405a326e8a55ae29325
Binary files /dev/null and b/dist/client/.DS_Store differ
bun patch --commit should probably ignore .DS_Store altogether.
bump
Still seeing this on OS: macOS 15.5 bun: 1.1.43
@zackradisic Can you take a look at this issue? Thank you.
Just confirming that https://github.com/oven-sh/bun/issues/13330#issuecomment-2831317868 also fixed the patch for me.
there is no .DS_Store patch and still not working OS: macOS 15.5 bun: 1.2.18
Is there any workaround or update on this?
Still an issue in
bun: 1.2.20
bun patch v1.3.0 (b0a6feca)
error: failed applying patch file: EACCES: Permission denied (mkdir())
error: failed to apply patchfile (patches/[email protected])
wsl2
still an issue in bun 1.3.1 on macos