15 04 2015
NPM, tmp and npm-xxx uncleaned paths
UPDATE: Created npm module to fix this stuff – https://www.npmjs.com/package/clean-npm-tmp
Today I came to work and it appeared that builds on our Jenkins ( CI environment ) are broken due to “No space left on device” error.
Further investigation showed that the whole /tmp folder was filled with strange “npm-xxx” folders, which in their turn are filled with the packages for npm.
It appears that there is an issue with npm https://github.com/npm/npm/issues/6855 and https://github.com/npm/npm/issues/6761 which doesn’t cleanup it’s temp folder when npm is done. I have tested it on 2.3.0 and it’s still there.
Thanks to the npm scripts, I could create ‘postinstall’ script, which would cleanup the leftovers. If you also suffer from this problem, you can just plug it into the package.json and it will help you keep your tpm folder clean.
It does respect the configuration of the npm if it points to the different location then “/tmp”. And it cleansup only the folder current “npm install” command has created.
If you don’t like oneliners, you also can create separate “npm-tmp-clean.sh” file showhere in projects’ bin folder and execute it through the “scripts”:
This script is a bit different then the one liner because npm runs the script in a separate process and finding the PID of the npm becomes a bit different.
I would strongly advice to use this oneliner in any project you run with npm, since you never may be sure, that your dependencies are not leaking into the /tmp folder. Or at least, make the cron job on the server to cleanup the /tmp folder if this is the preferred way of cleaning up things.
Important to note that this solution doesn’t work when using package on Windows.
“git root” – root folder of the git repository Conditional ie comments in react.js