Reputation: 1469
I am having an issue where after several restarts triggered by gulp watch, I get a warning that states I may have a memory leak. I assume it's because I am starting a new instance of gulp watch with every restart, triggering a new server and another new watch, over and over. I am not sure that's the case and not sure how to fix it if it is.
Here is my gulpfile.js.
const gulp = require('gulp');
const exec = require('child_process').exec;
const gutil = require('gulp-util');
const eslint = require('gulp-eslint');
gulp.task('dev', (() => {
gulp.start('test');
gulp.start('lint');
gulp.start('server');
gulp.start('watch');
return gutil.log('Gulp is running!');
}));
gulp.task('server', (cb) => {
exec('npm start', (err, stdout, stderr) => {
gutil.log(stdout);
gutil.log(stderr);
cb(err);
});
});
gulp.task('test', (cb) => {
exec('npm test', (err, stdout, stderr) => {
gutil.log(stdout);
gutil.log(stderr);
cb(err);
});
});
gulp.task('watch', () => {
gulp.watch(['./app.js', './views/*', './routes/*'], ['dev']);
});
gulp.task('lint', () => {
return gulp.src(['**/*.js', '!node_modules/**'])
.pipe(eslint())
.pipe(eslint.format());
});
And my error is:
(node:808) Warning: Possible EventEmitter memory leak detected. 11 change listeners added. Use emitter.setMaxListeners() to increase limit
Upvotes: 1
Views: 1778
Reputation: 3414
As another user noted, you're calling gulp dev
in gulp watch
basically creating an inifinity loop, which would cause that.
To add, I would encourage using a default task:
gulp.task('default', ['dev', 'test', 'lint', 'watch', 'server']);
Upvotes: 1
Reputation: 3551
Your gulp.watch
calls the task dev
which in turn creates another gulp.watch
. My money is on that.
Upvotes: 5