Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: EMFILE, too many open files with Gulp.watch

My gulpfile.js looks like this:

gulp.task('default', ['build', 'browser-sync'], function () {
    gulp.watch("**/*.css", ['bs-reload']);
    gulp.watch(["**/*.js", "!**/*/node_modules/**/*.*"], ['bs-reload']);
    gulp.watch("**/*.html", ['bs-reload']);
});

Even though I have excluded node_modules it is trying to add a watch to all node_modules.

How can exclude it?

Please note that the node_modules does not exist at root of the project, infect it is at above the root of the project, so why it is even bother including the same?

Error: EMFILE, too many open files '/Users/**/Documents/gits/tm/node_modules/browser-sync/lib/public/socket.io.js'
    at Object.fs.openSync (fs.js:438:18)
    at Object.fs.readFileSync (fs.js:289:15)
    at Object.utils.getSocketScript (/Users/**/Documents/gits/tm/node_modules/browser-sync/lib/snippet.js:109:19)
like image 709
codebased Avatar asked May 07 '15 09:05

codebased


1 Answers

Try this as a more resilient drop in replacement for fs:

graceful-fs

Globally patch fs like this:

var realFs = require('fs')
var gracefulFs = require('graceful-fs')
gracefulFs.gracefulify(realFs)
like image 175
Brett Postin Avatar answered Sep 19 '22 06:09

Brett Postin