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

孤人 提交于 2021-01-03 07:27:06

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!