title: TypeScript: Avoid require statements in compiled JavaScript
body: <p>In my TypeScript code I am using a third-party library called <a href="https://github.com/trentm/node-bunyan" rel="nofollow">bunyan</a> like so:</p>
  
  <pre><code>private logger: bunyan.Logger = bunyan.createLogger({name: "MyClass"});
  </code></pre>
  
  <p>Because TypeScript cannot resolve the variable <code>bunyan</code>, I do this to make the TypeScript compiler work:</p>
  
  <pre><code>import * as bunyan from "bunyan";
  </code></pre>
  
  <p>Unfortunately this causes the following JavaScript output:</p>
  
  <pre><code>var bunyan = require("bunyan");
  </code></pre>
  
  <p>The <code>require</code> statement will not work in the browser (when not using a <a href="http://requirejs.org/" rel="nofollow">requirejs</a> implementation), so I will receive: <code>Uncaught ReferenceError: require is not defined</code>.</p>
  
  <p>Actually I don't need the <code>require</code> statement in my compiled JavaScript because there is a <code>bunyan.min.js</code> (browserified version) which I can use for the browser. But how can I avoid the bunyan import in my TypeScript code without having the TypeScript compiler complaining about an unknown reference?</p>
  
  <p>I am using TypeScript 1.8 and this is my TypeScript compiler configuration:</p>
  
  <p><strong>tsconfig.json</strong></p>
  
  <pre><code>{
    "compilerOptions": {
      "module": "commonjs",
      "moduleResolution": "node",
      "noEmitOnError": true,
      "noImplicitAny": false,
      "removeComments": true,
      "target": "es5"
    },
    "exclude": [
      "node_modules",
      "typings/browser",
      "typings/browser.d.ts"
    ]
  }
  </code></pre>