avoiding npm install EEXIST lock errors

Oscar Brito

All nodejs developers use the following sentence when doing an npm i. If you don't use it, please start using it because it's almost as funny as the guy that downloaded the entire Internet to a CD.

wait a sec, npm is installing the entire internet

EEXIST error

Last week I was getting an EEXIST npm error where npm was complaining about the existence of some lock files during npm install.

npm ERR! EEXIST, open '...package-tgz.lock'  
File exists: '...package-tgz.lock  
Move it away, and try again.  

This behaviour was inconsistence and would happen anytime during the npm install. It could happen on any package during installation, but most of the times it was breaking on phantomjs or imagemin-*.

Note: I was using npm@1.4.28 from inside a Windows 10 virtual machine (yes Windows, I know!).

npm cache-lock

To solve this issue I found some npm github issues like #6309 where npm upgrades where suggested. I tried a couple of suggestion but none of them worked.

After a few hours of npm cache clean && npm i failures, I found the npm cache-lock configurations.

By incrementing the configuration values the issue was gone and npm install would succeed.

To do this add the following lines to your ~/.npmrc and run npm install again.

; avoid EEXIST lock errors
cache-lock-wait=30000  
cache-lock-retries=10  
cache-lock-stale=300000  

EOF

If you're experiencing this error I hope you find this post and avoid the same pain I went through.

To be honest I have no idea why this was happening and if the new npm version have this fixed. I suspect that it's something related to the file system synchronisation. Who knows!

Oscar out