var fs = require('fs');

// The number of files that we need to generate goog.require's for.
var numFiles = process.argv.length - 1;

/**
 * Object used a set of found goog.provide's.
 * @type {Object.<string, boolean>}
 */
var requires = {};

process.argv.forEach(function(val, index, array) {

  if (index === 0) {
    return;
  }

  fs.readFile(val, function(err, data) {
    if (err) {
      return;
    }

    var re = new RegExp('goog\\.provide\\(\'(.*)\'\\);');

    data.toString().split('\n').forEach(function(line) {
      var match = line.match(re);
      if (match) {
        requires[match[1]] = true;
      }
    });

    if (--numFiles === 0) {
      Object.keys(requires).sort().forEach(function(key) {
        process.stdout.write('goog.require(\'' + key + '\');\n');
      });
    }

  });

});

var fs = require('graceful-fs');

// The number of files that we need to generate goog.require's for.
var numFiles = process.argv.length - 1;

/**
 * Object used a set of found goog.provide's.
 * @type {Object.<string, boolean>}
 */
var requires = {};

process.argv.forEach(function(val, index, array) {

  if (index === 0) {
    return;
  }

  fs.readFile(val, function(err, data) {
    if (err) {
      return;
    }

    var re = new RegExp('goog\\.provide\\(\'(.*)\'\\);');

    data.toString().split('\n').forEach(function(line) {
      var match = line.match(re);
      if (match) {
        requires[match[1]] = true;
      }
    });

    if (--numFiles === 0) {
      Object.keys(requires).sort().forEach(function(key) {
        process.stdout.write('goog.require(\'' + key + '\');\n');
      });
    }

  });

});

Use graceful-fs in place of fs
Use graceful-fs in place of fs

Change generate-requires.js to use the graceful-fs module instead of fs. This is to avoid EMFILE errors on OSX because the maximum number of file descriptors have been reached.
