Skip to content

Conversation

@keegancsmith
Copy link
Contributor

Like EEXIST, we handle ENOTEMPTY when we fail to moveFile.

A user reported they consistently could not update our CLI tool. 1 In that report it always had the same file it tried to rename to. I believe what is happening here is when NPM retires an old version it renames it to a deterministic path. However, I suspect a previous update was interrupted leaving a non-empty directory at the destination.

When googling ENOTEMPTY all the results seem to be about npm failures with users suggesting clearing out node_modules. Maybe this will also solve those issues.

Like EEXIST, we handle ENOTEMPTY when we fail to moveFile.

A user reported they consistently could not update our CLI tool. [1] In
that report it always had the same file it tried to rename to. I believe
what is happening here is when NPM retires an old version it renames it
to a deterministic path. However, I suspect a previous update was
interrupted leaving a non-empty directory at the destination.

When googling ENOTEMPTY all the results seem to be about npm failures
with users suggesting clearing out node_modules. Maybe this will also
solve those issues.

[1]: https://gist.github.com/keegancsmith/5dac339583cc127031da6ed0e8512d47
@keegancsmith keegancsmith requested a review from a team as a code owner November 4, 2025 10:09
Copy link
Contributor

@owlstronaut owlstronaut left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good fix for a real user problem. Extending the EEXIST recovery logic to also handle ENOTEMPTY makes sense - both indicate the retirement path already has content from a previous interrupted install. Test coverage looks solid. Thanks!

@owlstronaut owlstronaut merged commit 0765289 into npm:latest Dec 5, 2025
16 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants