There may be a problem with a package you are using, not npm itself. Sigh. Deep breath. Grunt. Okay - time to wipe the node_modules
and start again.
Reasons aside, for now, there are a few commands I seem to run almost daily to try to recover from errors. Kelly Vaughn got me thinking this morning about this.
if at first you don't succeed, try
โ Kelly Vaughn ๐ (@kvlly) April 22, 2019rm -rf node_modules && npm install
There are a few contributing factors to me running into issues with npm packages.
- I manage a lot of code, including some I touch infrequently enough where the packages get stale.
- I work in coffee shops and poor WiFi areas quite often (good WiFi one minute, poor the next)
- I have supported 1000+ developers using Node.js with npm
- Murphy's Law surrounds me
Maybe they donโt affect you - in which case - thatโs great!
So what do I do when I see one of the issues with my npm packages? Especially the ones that claim there may be something wrong with one of the packages and not npm itself? I clear the node_modules
folder and try again.
rm -rf node_modules package-lock.json
npm install
And to do it with flair, I created a bash alias to run these commands.
npm-wipe
npm i
Why run it in two commands? Mostly because I like to see that the first one completed then go run npm install
manually. I have no good reason. You may prefer to run it all at once.
Bash Alias
Here is how I set up my bash alias on my macOS.
alias npm-wipe="rm -rf node_modules package-lock.json"
Hope this helps you out of a bind once in a while, too! Do you use this technique? If not, what do you do when npm errors bite you?