npm tried to rename a staging folder that had already been removed (cleanup, AV, or race). Clean node_modules/cache, stop concurrent installs, and reinstall once.
Fixes npm ERR! Error: ENOENT: no such file or directory, rename 'node_modules/.staging'
rm -rf node_modules package-lock.json
npm cache clean --forcerm -rf node_modules package-lock.jsonnpm cache clean --forcenpm ERR! Error: ENOENT: no such file or directory, rename 'node_modules/.staging'
npm writes temp content under node_modules/.staging and then renames it into place. If another process deletes .staging (cleanup script, AV, concurrent npm), the rename target disappears and npm throws ENOENT. It also occurs when node_modules is mounted from an empty host volume, or when previous failed installs left partial folders that get removed mid-run. Running multiple npm installs in parallel is a common trigger.
Ensure only one npm/yarn/pnpm process runs in the project. Stop scripts that auto-clean node_modules.
rm -rf node_modules package-lock.json
npm cache clean --forceAdd a Defender/AV exclusion for the project during installation so .staging is not removed mid-run.
In Docker/CI, do not mount an empty host node_modules over the container path. Build dependencies inside the image or mount only source.
npm cinpm is not safe to run in parallel on the same tree; run installs sequentially. In CI, avoid cleaning node_modules mid-install (e.g., concurrent cache warmers). If you need per-step isolation, install in a fresh workspace each time. Docker Compose users should mount only source and keep node_modules inside the image or a dedicated volume to prevent disappearing .staging directories.