Saturday, January 5, 2013

Brewing Nodejs

Lately I ran into an issue while doing a 'brew upgrade' on my mac. Homebrew upgraded nodejs from 0.8.4 to 0.8.16. It was a very bad time for me to do this update since I was pretty much in the middle of a very important nodejs development and all the setup was working well enough... In fact I was willing to do a 'update' of brew and ended up typing 'upgrade' ... !#?@


Anyways, at the end of the whole upgrade process I took a time to re-read the operation log and hunt for errors or warning just in case. How wise! node and npm where not completely installed, the links in /usr/local/bin where not made. See:

Error: The `brew link` step did not complete successfully
The formula built, but is not symlinked into /usr/local
You can try again using `brew link node'

So I tried the recommended command:

$ brew link node
Linking /usr/local/Cellar/node/0.8.16... Warning: Could not link node. Unlinking...

Error: Could not symlink file: /usr/local/Cellar/node/0.8.16/bin/npm
Target /usr/local/bin/npm already exists. You may need to delete it.
To force the link and delete this file, do:
 brew link --overwrite formula_name

To list all files that would be deleted:
 brew link --overwrite --dry-run formula_name

Tadaaaa!

$ brew link --overwrite node
Linking /usr/local/Cellar/node/0.8.16... Warning: Could not link node. Unlinking...

Error: Permission denied - /usr/local/lib/node_modules/npm/node_modules/read-package-json/README.md

Fu@@!  ... (Why didn't I press CTRL-C when I noticed I typed a 'upgrade' instead of 'update'.)

$ sudo brew link node
Password:
Error: Cowardly refusing to `sudo brew link'
You can use brew with sudo, but only if the brew executable is owned by root.
However, this is both not recommended and completely unsupported so do so at
your own risk.

Thanks Max ;) that was dumb anyways...

From this point I entered hardcore make-it-work-by-any-mean mode! So please don't flame me :)

Here is what I did. I can tell you right away that it worked and probably can help you if you ever get yourself in the same messy state I was but it may not be the preferred way to solve this. So if you have a better way I'm all ears in the comments.

  • First I notices that the /usr/local/lib/node_modules was the global modules' dir of the 0.8.4 version. So I moved it to node_modules.0.8.4.
  • Then I redid the 'brew link --overwrite node' and It worked!
  • Then I checked 'which' node and npm  ... Ok my PATH was still good!
  • Then I checked node and npm versions ... Ok it's the new ones!
  • Then I tried to reinstall all my required global modules with npm ... Ok!
  • Then I ran 'node' and required one of the installed modules... Not Ok!

The module was not found although I could see it in the output log of 'npm list -g'

 !  I noticed that the node_modules dir as reported by npm was now /usr/local/share/npm/lib/node_modules (Was it changed by the new formula?)

So I updated my NODE_PATH environment variable to this path. And now it's working!

Cheers.



No comments:

Post a Comment