title: Why doesn't Node.js find a module in node_modules?
body: <p>I'm trying to get <a href="https://github.com/squaremo/amqp.node/blob/master/examples/tutorials/send.js" rel="nofollow">this AMQP example</a> working on OSX. What I did:</p>
  
  <pre><code>$ npm install amqplib
  $ npm list
  /Users/andrewendt/tmp/amqplib
  └─┬ amqplib@0.3.2
    ├── bitsyntax@0.0.4
    ├── buffer-more-ints@0.0.2
    ├─┬ readable-stream@1.1.13
    │ ├── core-util-is@1.0.1
    │ ├── inherits@2.0.1
    │ ├── isarray@0.0.1
    │ └── string_decoder@0.10.31
    └── when@3.6.4
  </code></pre>
  
  <p>The example <code>send.js</code> starts with:</p>
  
  <pre><code>var amqp = require('amqplib');
  var when = require('when');
  </code></pre>
  
  <p>and I get this error:</p>
  
  <pre><code>$ node send.js
  module.js:338
      throw err;
            ^
  Error: Cannot find module 'when'
      at Function.Module._resolveFilename (module.js:336:15)
      at Function.Module._load (module.js:278:25)
      at Module.require (module.js:365:17)
      at require (module.js:384:17)
      at Object.&lt;anonymous&gt; (/Users/andrewendt/tmp/amqplib/send.js:4:12)
      at Module._compile (module.js:460:26)
      at Object.Module._extensions..js (module.js:478:10)
      at Module.load (module.js:355:32)
      at Function.Module._load (module.js:310:12)
      at Function.Module.runMain (module.js:501:10)
  </code></pre>
  
  <p>Note: I can <code>require('amqplib');</code> just fine. I can reproduce this using the interactive console.</p>
  
  <p>I'm totally stumped. Why doesn't Node.js find this module when it's a dependency of something it <em>does</em> find?</p>