Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

node.js on Windows frequently fails with 'EMFILE: too many open files'

When using various tools on Windows, eg browserify, I frequently see:

Error: EMFILE: too many open files, open 'C:\Users\mike\Documents\myapp\node_modules\babel-polyfill\node_modules\core-js\package.json'
    at Error (native)

Unlike Linux, where maximum open files is a soft limit that chan be changed, it seems EMFILE is a hard limit in Windows.

How can I fix this?

note: I have solved the problem, but it took a week and I couldn't find anything on the internet when I searched, so I'm about to put the answer here for the next node-Windows person

like image 403
mikemaccana Avatar asked Jun 29 '16 12:06

mikemaccana


1 Answers

The graceful-fs module can be used to limit the amount of file IO, slowing things down a little but avoiding node crashes due to EMFILE.

// Monkey-patch real fs module, so all I/O uses graceful FS.
var fs = require('fs')
var gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(fs)
like image 150
mikemaccana Avatar answered Oct 11 '22 05:10

mikemaccana