npm EPERM "operation not permitted" - Fix Locked/Read-Only Files in CI
By Kaveh Alemi·Latchkey
EPERM means the operating system refused a file operation npm attempted - usually an unlink or rename inside node_modules. The file is locked, read-only, or owned by a user npm is not running as.
What this error means
npm fails with npm error path ... and EPERM: operation not permitted, unlink/rename. It is common on read-only mounts, root-owned files in Docker, or when another process holds the file.
Ensure no other step or watcher is touching node_modules during install.
Install into a writable directory, not a read-only volume.
In images, run npm as the same user that owns the workspace.
How to prevent it
Keep node_modules owned by the build user.
Install on writable layers/mounts only.
Avoid concurrent processes touching node_modules.
Frequently asked questions
What causes ""EPERM: operation not permitted""?
A node_modules created by root (or on a read-only mount) cannot be modified by the non-root build user, so unlink/rename is denied.
How do I fix "EPERM: operation not permitted"?
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.