问题
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
回答1:
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)
来源:https://stackoverflow.com/questions/38099671/node-js-on-windows-frequently-fails-with-emfile-too-many-open-files