Some time ago I had trouble with the npm cache on our build machines. From time to time we had to do npm cache clean
by hand, and that solved various issues that we
In my case, i was facing similar issue while running multiple instance of 'npm install' on VM used for build(Windows)
Since it was a VM used only for build there was no other program locking the files. I tried disabling various antivirus settings which didn't worked. "npm cache clear" and "npm cache verify" worked but it was not a right solution for me as i cannot guess when somebody will trigger a build job from Jenkins for different release/environment leading to multiple instance of 'npm install' and hence i cannot add it to the build script nor i can go login to VM and clear/delete the cache folders manually every time.
Finally, after some research, I ended up running "npm install" with separate cache path for each job using following command:
npm install --cache path/to/some/folder
Since, all the jobs running at the same time now had a separate cache path rather than the common global path (Users/AppData/Roaming/), this issue got fixed as the jobs were no more trying to lock and access the same file, from the common npm cache.
Please note you can install a single package with a cache path as follows:
npm install packageName --cache path/to/some/folder
I was not able to find this way of giving a cache path in npm documentation but i gave it a try and it worked. I am using npm6 and looks like it works since npm5 as @ArchNoob mentioned in the comment