You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Can't create new dependency patch using linker = "isolated" #21212
➜ bun patch example
bun patch v1.2.19 (aad3abea)
4 packages installed [50.00ms]
To patch example, edit the following folder:
node_modules/example
Once you're done with your changes, run:
bun patch --commit 'node_modules/example'
➜ bun patch --commit 'node_modules/example'
bun patch v1.2.19 (aad3abea)
error: failed to parse patchfile: bad_file_mode
error: failed to apply patchfile (patches/example@0.0.0.patch)
Checked 177 installs across 189 packages (no changes) [31.00ms]
➜ bun patch example
bun patch v1.2.19 (aad3abea)
error: failed to parse patchfile: bad_file_mode
error: failed to apply patchfile (patches/example@0.0.0.patch)
Checked 177 installs across 189 packages (no changes) [14.00ms]
error: error overwriting folder in node_modules: FileNotFound
Additional information
existing patches seems to work
Reacted by Killian Guibout-Chatelain, Antony Derham, Arsh, Net, Julen Ruiz Aizpuru, Sameh Amnoun and Nikita Koynov
I've reproduced this issue and identified the root cause. The problem occurs because when using --linker=isolated, Bun creates symlinks in node_modules/ that point to packages in the isolated cache. The patch system expects regular files/directories but encounters symlinks, causing several issues:
Git diff includes symlink metadata: The generated patch contains new file mode 120000 (symlink mode) instead of actual file content
Patch parser fails: The bad_file_mode error occurs in src/patch.zig:524 because the patch parser doesn't handle symlink modes
File operations fail: Subsequent patch operations fail with FileNotFound because the system tries to operate on broken symlinks
Implementation Plan
Here's a comprehensive fix approach:
1. Detect Symlinked Packages in Patch Commands
Files to modify: src/install/PackageManager/patchPackage.zig
In preparePatch() (~line 546): Detect if the target package folder is a symlink
In doPatchCommit() (~line 12): Add symlink detection for both path and name-based arguments
2. Resolve Symlinks Before Git Operations
Files to modify: src/install/PackageManager/patchPackage.zig
In doPatchCommit(), before calling gitDiffPreprocessPaths() (~line 330):
Check if changes_dir is an isolated symlink
If so, resolve to the actual cache directory path
Use the resolved path for git diff operations
3. Enhance Patch File Mode Parsing
Files to modify: src/patch.zig
Update parseFileMode() (~line 657) to handle symlink modes gracefully
Add symlink mode constants and handling logic
4. Update Error Handling
Files to modify: src/patch.zig
Improve error messages to indicate symlink-related issues
Add specific guidance for isolated linker mode
5. Add Integration Tests
Files to create: test/regression/issue/21212-patch-isolated-symlinks.test.ts
Test patching packages installed with --linker=isolated
Verify both patch creation and application work correctly
Test error scenarios and edge cases
Testing Strategy
Unit Tests: Test symlink detection and resolution functions
Integration Tests: Full patch workflow with isolated packages
As a workaround, you can temporarily not use the isolated strategy, reinstall all the dependencies, then generate the patch and --commit it. After that, the patched package will be stored in the cache and you can set the isolated setting again. In my case this worked and I have my patched dependency successfully installed with isolated dependencies, even if I delete all node_modules in my workspace and reinstall again it works seamlessly.
Fixed in #23311, and will be included in Bun v1.3 when it's released. In the meantime you can also use a canary build that has the bug fix (bun upgrade --canary).
Closing as complete. Please comment on this issue if you continue to have issues with patches and isolated installs, or create a new issue.
Activity
linear commentedon Jul 20, 2025
ENG-19695 Can't create new dependency patch using `linker = "isolated"`
Fix bun patch failure with --linker=isolated
robobun commentedon Aug 13, 2025
Analysis
I've reproduced this issue and identified the root cause. The problem occurs because when using
--linker=isolated, Bun creates symlinks innode_modules/that point to packages in the isolated cache. The patch system expects regular files/directories but encounters symlinks, causing several issues:new file mode 120000(symlink mode) instead of actual file contentbad_file_modeerror occurs insrc/patch.zig:524because the patch parser doesn't handle symlink modesFileNotFoundbecause the system tries to operate on broken symlinksImplementation Plan
Here's a comprehensive fix approach:
1. Detect Symlinked Packages in Patch Commands
Files to modify:
src/install/PackageManager/patchPackage.zigpreparePatch()(~line 546): Detect if the target package folder is a symlinkdoPatchCommit()(~line 12): Add symlink detection for both path and name-based arguments2. Resolve Symlinks Before Git Operations
Files to modify:
src/install/PackageManager/patchPackage.zigdoPatchCommit(), before callinggitDiffPreprocessPaths()(~line 330):changes_diris an isolated symlink3. Enhance Patch File Mode Parsing
Files to modify:
src/patch.zigparseFileMode()(~line 657) to handle symlink modes gracefully4. Update Error Handling
Files to modify:
src/patch.zig5. Add Integration Tests
Files to create:
test/regression/issue/21212-patch-isolated-symlinks.test.ts--linker=isolatedTesting Strategy
Alternative Approaches Considered
This fix should resolve the issue while maintaining compatibility with existing patch workflows.
i-love-neko-girls commentedon Aug 14, 2025
thank you claude can you fix it then
iivvaannxx commentedon Oct 10, 2025
As a workaround, you can temporarily not use the
isolatedstrategy, reinstall all the dependencies, then generate the patch and--commitit. After that, the patched package will be stored in the cache and you can set theisolatedsetting again. In my case this worked and I have my patched dependency successfully installed with isolated dependencies, even if I delete allnode_modulesin my workspace and reinstall again it works seamlessly.dylan-conway commentedon Oct 10, 2025
Fixed in #23311, and will be included in Bun v1.3 when it's released. In the meantime you can also use a canary build that has the bug fix (
bun upgrade --canary).Closing as complete. Please comment on this issue if you continue to have issues with patches and isolated installs, or create a new issue.