my tale of npm woe – when all else fails, clear you cache!

Tonite was one of those “fun” times as a software developer. By fun, I mean one of those moments when you seriously think about having another profession due to hours of frustration trying to debug something, aaargh! My buddy Howard Dierking and I have a running joke that we’re going to open an ice cream shop which tonight sounded like a great idea.

If you have no patience to read my torturous experience,  jump to the end of the post.

Back to my tale of woe. Tonight I started off with the intent of porting an app that I originally I wrote in .NET to Node. The app has both a web api and a jQuery front end. I was pretty excited about getting some hardcore coding time and even tweeted about the modules I was planning to use namely expressjs, socket.io, restify and mocha for my tests. So as I usually do, I created an empty folder, and then went and installed my modules. Everything worked grand until I got to install restify. When I did, it failed gloriously with the following hideous error.

What the??? OK, well that obviously did not work. So then I went and deleted my node_modules folder and installed again. Same error.

OK, well let me try installing a previous version. “npm install node-uuid@1.3.2″. Works! In the future I’ll know that was a big clue, unfortunately not this time. Instead I thought node-uuid _itself_ had a problem. OK, so next I went to the restify git repo and pulled down all the code. I then change the package.json for node-uiid to 1.3.2, then npm install restify and it works perfectly! Aha, it MUST be something wrong with node-uuid 1.3.3 right! I think so, so I head over to github and open an issue.

I then tweet about the issues I am having. Einar Otto (socket.io) graciously steps in to help me out. We’re on skype together trying to figure out just what is wrong. First thing he does on his side is “npm install restify” and what do you know it works. I then jump over to my mac book pro (my other mac) and do the same and it also works! Ah, so now we think it’s something possibly due to my machine which is an iMac from mid 2010, it could be Einar says because I am using the prebuilt version of node, I should build the source. I also start speculating completely crazy ideas, like maybe somehow it has to do with my username having an underscore. Yes folks, I became delirious.

Building the source doesn’t work, switching to different folders doesn’t work, trying like 5 versions of node doesn’t work, nothing works!!!!!!!!

And then hours later, just when I am about to accept defeat and switch off my nice 21″ imac to use my mbp, Einar says “Hmm, I wonder if maybe you should clear you cache”

What? Of course, npm has a local cache for modules that are installed so that it does not have to get them every time. Einar tells me where the cache is and I clear it. Then the moment of truth, “npm install restify”

That was it! Some module turd stuck in my cache!

Moral of the story, when something seems fishy with a module you are installing, you’ve tried everything and nothing else seems to work, clear you cache! It might save you from switching professions.

npm cache clean

Isaac if you are listening, it would be nice if there was some way npm detected repeated failures and prompted the user to clean the cache. That will save node devs a lot of frustration!

This entry was posted in node.js. Bookmark the permalink. Follow any comments here with the RSS feed for this post.
  • Travis Wimer

    It’s been several years, and unfortunately this is still a problem. Thanks for helping me avoid wasting 5 hours!

  • http://buwilliams.tumblr.com/ Buddy Williams

    Yeah, this happened to me. Sadly, I didn’t find this post quickly. I spent about 6 hours going insane. Therefore, sir if you are ever in town (Atlanta, GA) I shall bestow your favorite beverage.

  • http://blogs.msdn.com/gblock Glenn Block

    Thanks everyone for the comments. I am happy to hear the post has proved useful!

  • http://markthethomas.github.io/ markthethomas

    Found this to be a solution for more than a few npm errors I’ve encountered (and caused, to be fair) :)

  • fairmountfair

    You are my favorite person on the internet right now. Thank you so much.

  • Jon de la Motte

    Bless your heart my friend, this just saved my day.

  • Rohan Nicholls

    Thank you so much.  Just saved me giving up and going home in disgust.

  • http://thunki.com Nils N. Haukås

    Fantastic post! I was also trudging through a land of woe when I thankfully stumbled upon your tip on clearing the npm cache. 

  • James Sun

    Thanks for your blog post. I, too, was experiencing weird behavior when trying to install a package via NPM.

  • http://twitter.com/fijiaaron Aaron Evans

    I’ve seen stuff like this.
    I’m looking for a way to have CI builds specify a separate npm cache for each build so it can avoid these sort of problems.

  • Glenn Block

    Kelsey I am sorry to hear that. I hope you didn’t spend as much time / have as much paind as I did.

  • Anonymous

    I had the same issue. :)