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 firstname.lastname@example.org″. 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!