title: How do I prevent browserify from including multiple versions of sub-dependencies?
body: <p>In my front-end code, I use <code>require()</code> to pull in libraries which, in turn, depend on different versions of Underscore.js. As a result, when I use browserify to bundle everything together, the output contains multiple copies of Underscore. Is there a way to tell browserify that <code>require('underscore')</code> should always import a particular file?</p>
  
  <p>As a demonstration of the problem, imagine I have the following dependencies:</p>
  
  <pre><code>// package.json
  "dependencies": {
    // Depends on underscore 1.7.0
    "backbone": "^1.1.2",
  
    // Depends on underscore 1.6.0
    "backbone.marionette": "^2.3.0"
  }
  </code></pre>
  
  <p>In <code>main.js</code> I use both libraries:</p>
  
  <pre><code>// main.js
  var Backbone = require('backbone');
  var Marionette = require('backbone.marionette');
  console.log("Hello, world!");
  </code></pre>
  
  <p>When I create a bundle, multiple versions of Underscore are included:</p>
  
  <pre><code>PS&gt; browserify main.js -o out.js
  PS&gt; findstr _.VERSION out.js
    _.VERSION = '1.7.0';
    _.VERSION = '1.6.0';
  </code></pre>
  
  <p>(<a href="https://github.com/brantb/browserify-duplicate-libs">I created a GitHub repository with a more complete example</a>. Clone it and run <code>npm install &amp;&amp; npm test</code> to see it in action)</p>
  
  <p>I tried adding a <code>browser</code> section to my <code>package.json</code> like the following, but it didn't seem to have any effect:</p>
  
  <pre><code>// package.json
  "browser": {
    "underscore": "./node_modules/underscore/underscore.js"
  }
  </code></pre>
  
  <p>I understand why <code>npm</code> installs duplicate dependencies (and it makes sense to do it this way for server-side code) but what's the correct way to deal with this when using browserify?</p>