title: uglifying underscore breaks sourcemaps during browserify
body: <p><a href="https://stackoverflow.com/questions/31055660/browserify-source-map-not-working-if-require-underscore">Related, but unanswered.</a></p>
  
  <p>In my NPM project, I have the following folder <code>public</code>:</p>
  
  <pre><code>sourcemaps $ tree public/
  public/
  ├── index.html
  ├── js
      ├── bar.js
      ├── foo.js
      ├── main.js
  </code></pre>
  
  <p>In <code>bar</code>:</p>
  
  <pre><code>'use strict';
  
  var go = module.exports = function () {
    return 'hey, I am bar';    
  };
  </code></pre>
  
  <p>In <code>foo</code>:</p>
  
  <pre><code>'use strict';
  
  var bar = require('./bar');
  
  var go = module.exports = function () {
    console.log(bar());  
  };
  </code></pre>
  
  <p>In <code>main</code>:</p>
  
  <pre><code>'use strict';
  
  var foo = require('./foo');
  
  foo();
  </code></pre>
  
  <p>I have a node script that uglifies and creates sourcemaps:</p>
  
  <pre><code>var bundle_map = 'public/js/bundle-map.json'
    , stream = ''
    , browserify = require('browserify')
    , exorcist = require('exorcist')
    , uglifyjs = require('uglify-js')
    , fs = require('fs');
  
  browserify({entries: 'public/js/main.js', debug: true})
  .bundle()
  .pipe(exorcist(bundle_map))
  .on('data', function(chunk) {
    stream += chunk;
  })
  .on('end', function() {
    var minified = uglifyjs.minify(stream, {
      fromString: true,
      inSourceMap: bundle_map,
      outSourceMap: 'bundle-min.map'
    });
  
    fs.writeFile('public/js/bundle-min.js', minified.code);
    fs.writeFile('public/js/bundle-min.map', JSON.stringify(JSON.parse(minified.map)));
  });
  </code></pre>
  
  <p><code>index</code>:</p>
  
  <pre><code>&lt;html lang="en"&gt;
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
      &lt;title&gt;&lt;/title&gt;
  &lt;/head&gt;
  &lt;body&gt;
      &lt;script src="js/bundle-min.js"&gt;&lt;/script&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  </code></pre>
  
  <p>I get the source maps fine when serving the site through <a href="http://www.rubydoc.info/github/rack/rack/Rack/Static" rel="nofollow">Rack::Static</a>. Here's <code>config.ru</code>:</p>
  
  <pre><code>use Rack::Static, :urls =&gt; ["/js"], :root =&gt; "public"
  
  run lambda { |env|
    [
      200,
      {
        'Content-Type'  =&gt; 'text/html',
        'Cache-Control' =&gt; 'public, max-age=86400'
      },
      File.open('public/index.html', File::RDONLY)
    ]
  }
  </code></pre>
  
  <p>But when I <code>npm install underscore</code> in the <code>sourcemaps</code> directory, I don't get source maps.</p>
  
  <p>Does anyone know why this happens? I don't get any errors in the Chrome console, either, and I see the source maps downloading fine in both cases:</p>
  
  <pre><code>127.0.0.1 - - [15/Jul/2015 19:26:55] "GET /js/bundle-min.js HTTP/1.1" 304 - 0.0003
  127.0.0.1 - - [15/Jul/2015 19:26:55] "GET /js/bundle-min.map HTTP/1.1" 304 - 0.0003
  127.0.0.1 - - [15/Jul/2015 19:26:55] "GET /favicon.ico HTTP/1.1" 200 - 0.0005
  </code></pre>
  
  <p>Requiring other node modules (<code>react</code>, e.g., or <code>exorcist</code>) and leaving <code>underscore</code> out gets me the source maps in Chrome Developer tools just fine.</p>
  
  <p>Also, taking <code>uglify-js</code> out of the stream pipeline but leaving <code>underscore</code> in gives me the right sourcemaps! Hm...</p>