fix: use graceful-fs to retry transient EPERM/EACCES/EBUSY on Windows rename#228
Open
manzoorwanijk wants to merge 1 commit intonpm:mainfrom
Open
Conversation
graceful-fs patches fs.rename on Windows with exponential backoff for EACCES/EPERM/EBUSY, fixing failures caused by antivirus or indexer file locks during concurrent writes. Fixes npm#227
This was referenced Feb 24, 2026
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
On Windows,
fs.renamefails withEPERM: operation not permittedwhen another process (Windows Defender, Windows Search indexer, or a concurrent Node.js worker) holds a transient lock on the target file. This is especially prominent with npm'sinstall-strategy=linked, where many files are written in parallel under a single.store/directory, increasing the window for antivirus lock conflicts.The root cause is that
write-file-atomicuses barerequire('fs'), which has no retry logic.graceful-fsalready patchesfs.renameon Windows with exponential backoff (up to 60s) for EACCES/EPERM/EBUSY errors (polyfills.js#L96-L120).This PR switches from
require('fs')torequire('graceful-fs')to get that retry behavior.Background
graceful-fswas originally a dependency ofwrite-file-atomicbut was removed in v3.0.0 to break a circular dependency that interfered withgraceful-fs's own test suite (isaacs/node-graceful-fs#163). That circular dependency no longer exists sincetapno longer depends onwrite-file-atomic.Changes
require('fs')torequire('graceful-fs')graceful-fs(^4.2.11) as a dependencyt.mock()calls to mock'graceful-fs'instead of'fs'Related issues
npm installon Windows with npm 10.xReferences
Fixes #227, #28