Running npm install shouldn't take an hour
Recently on several projects, I found that once I had forked and cloned the repo from GitHub, when I ran bower install
and npm install
to pull in all the dependencies for the project, things went smoothly until I ran npm install
and the installation would get most of the way done (seemingly) and then just hang on me. Eventually it would generally finish up but not always. I decided to investigate and after hours of StackOverflow and googling, I came upon this simple solution.
I should mention that when I would exit out of an npm install
operation with Control + c
, when I reran npm install
, it appeared to be looking at some cache someplace to see what had already been installed and would complete quite quickly. But, when I tried to run the project with node server.js
, I would see errors on the console that certain modules were missing. Obviously my npm install
had hiccupped someplace.
Don't delete node_modules from Finder
After cancelling out of npm install
, one might try to brute force and delete node_modules
folder in Mac OSX finder. Better to just delete the npm package directory but do it from the command line using this command when you are in the node_modules folder from the command line.
rm -r <directoryName>
The rm
is the remove (or delete) command and the -r
is the recursive flag that says to delete all files and directories within the outer directory you specify.
Clear the npm cache
The final step is to clear the npm cache with this command.
npm cache clean
And that's it. Now run npm install
and see if that doesn't just clear up your little hanging problem.