npm "EPERM: operation not permitted, rename" - Fix Staging Rename in CI
By Kaveh Alemi·Latchkey
npm stages a package then renames it into node_modules. An EPERM specifically on that rename means the OS refused the move - the target is locked, read-only, owned by another user, or held open by another process.
What this error means
npm fails with EPERM: operation not permitted, rename on a .staging/<pkg> path. It is common on Docker with root-owned node_modules, on read-only mounts, or when a file watcher/antivirus holds the file.
Ensure no watcher/antivirus holds files under node_modules during install.
Install on a writable layer, not a read-only volume.
Run npm as the user that owns the workspace.
How to prevent it
Keep node_modules owned by the build user.
Install on writable layers only.
Avoid concurrent processes holding module files.
Frequently asked questions
What causes ""EPERM … rename""?
A node_modules created by root (or on a read-only mount) cannot be modified by the non-root build user, so the staging rename is denied.
How do I fix "EPERM … rename"?
Hand node_modules back to the build user and reinstall on a writable path.
Can Latchkey fix this automatically?
Yes. Latchkey runs your GitHub Actions on managed runners that detect this failure, apply the fix, and retry the job automatically - self-healing is on by default.