MacOS npm installation fails with graceful-fs module error

I’m running into issues while setting up npm on my MacBook Pro. My system is running OS X 10.6.6 and I have Xcode 3.2 installed. When I try to use the curl command to install npm, it starts downloading but then crashes with multiple errors about a missing ‘graceful-fs’ module. The error happens repeatedly during the installation process and eventually fails completely. I’m not sure what’s causing this dependency issue or how to fix it. Has anyone encountered this problem before and found a solution?

iMac:project john$ curl http://npmjs.org/install.sh | bash
  % Total    % Received % Xferd  Average Speed   Time    Time     Time  Current
                                 Dload  Upload   Total   Spent    Left  Speed
100  3902  100  3902    0     0   4114      0 --:--:-- --:--:-- --:--:--  7898
downloading: http://registry.npmjs.org/npm/-/npm-1.0.22.tgz

node.js:63
    throw e;
    ^
Error: Cannot find module 'graceful-fs'
    at Function.loadModule (node.js:275:15)
    at Function.require (node.js:411:14)
    at Object.<anonymous> (/private/var/folders/Xy/XyaHxaDzGB8Hcw2FWL3FpE+++TI/-Tmp-/npm.12345/package/lib/utils/json-reader.js:7:10)
    at Module._compile (node.js:462:23)
    at Module._loadScriptSync (node.js:469:10)
    at Module.loadSync (node.js:338:12)
    at Function.loadModule (node.js:283:14)
    at Function.require (node.js:411:14)
    at Object.<anonymous> (/private/var/folders/Xy/XyaHxaDzGB8Hcw2FWL3FpE+++TI/-Tmp-/npm.12345/package/bin/package-reader.js:9:16)
    at Module._compile (node.js:462:23)
Installation failed
iMac:project john$

This is a classic circular dependency issue with older npm versions. The graceful-fs module is essential for npm to work, but your install script can’t recognize it properly. I’ve hit the same problem on OS X 10.6 before - downloading Node.js directly from nodejs.org fixed it for me. The curl method sucks at resolving dependencies on older systems. Node.js comes with npm bundled, so installing it properly should kill these module errors. Just make sure you wipe out any broken npm installs first before trying the Node.js installer.

I hit this same issue on an older MacBook. The problem is npm can’t find its core dependencies during installation. Skip the curl method and download the Node.js source code instead - build it manually with make install. This bypasses the broken install script and compiles everything properly for your system. Make sure you’ve got the latest Xcode developer tools first since some builds need updated compiler components. Takes longer but it’s way more reliable on older OS X versions where the automated installers choke on dependencies.

Yeah, I remember this pain! Try installing an older npm version manually first - grab 0.3.x or something that doesn’t need graceful-fs. Once that’s working, you can upgrade step by step to newer versions. Your Xcode might also be too old for some of the compilation stuff.