title: TypeScript cannot find module if it contains a require
body: <p>I'm trying to understand how to properly work with TypeScript and classic JS node modules.</p>
  
  <p>I set up a very basic project, with the following file architecture:</p>
  
  <pre><code>.
  ├── index.ts
  ├── lodash.d.ts
  ├── module.ts
  └── node_modules
      └── lodash
  </code></pre>
  
  <p><code>lodash</code> has been installed with <code>npm</code>. As it seems to provide no typings info, I wrote a basic <code>d.ts</code> file that only describes one function, just to please <code>tsc</code> and avoid error about not knowing <code>lodash</code>.</p>
  
  <p><strong>lodash.d.ts</strong></p>
  
  <pre><code>declare module "lodash" {
    export function reverse(array: any[]): any[];
  }
  </code></pre>
  
  <p>In my <code>module.ts</code> file, I import lodash with <code>require</code> and expose a function on a module, which I use on <code>index.ts</code> file.</p>
  
  <p><strong>module.ts</strong></p>
  
  <pre><code>/// &lt;reference path="./lodash.d.ts" /&gt;
  
  import _ = require('lodash');
  
  module FooModule {
    export function foo() {
      return _.reverse([1, 2, 3]);
    }
  }
  </code></pre>
  
  <p><strong>index.ts</strong></p>
  
  <pre><code>/// &lt;reference path="./module.ts" /&gt;
  
  let a = FooModule.foo();
  console.log(a);
  </code></pre>
  
  <p>The problem is that <code>tsc</code> (and so VS Code) tells me that it can't find name <code>FooModule</code>.</p>
  
  <pre><code>$ tsc index.ts --module commonjs -outDir build
  index.ts(3,9): error TS2304: Cannot find name 'FooModule'.
  </code></pre>
  
  <p>However, if I remove the <code>import _ = require('lodash');</code> from <code>module.ts</code>, it works correctly (except the obvious fact that <code>_</code> variable is now undefined).</p>
  
  <p>Am I doing something wrong with this <code>require</code>?</p>