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.

npm-node-errors-1

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 from her post on Twitter

There are a few contributing factors to me running into issues with npm packages.

  1. I manage a lot of code, including some just infrequent enough where the packages get stale.
  2. I work in coffee shops and poor WiFi areas quite often
  3. Murphy's Law surrounds me

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!