gulp-watch-error-on-ubuntu-14.04

Posted by flow is me on 2016-01-14

在折腾自己的gulp-angular 项目脚手架的时候,配合 liveReload 插件实现实时页面刷新功能,因为gulp.watch本身存在性能问题,所以采用了gulp-watch 插件来代替gulp.watch, 在测试liveReload的时候发现出现以下错误提示:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
Message:
An error occured in task 'watch'.
events.js:141
throw er; // Unhandled 'error' event
^
Error: watch /home/flow/angular-pro-template/app/styles ENOSPC
at exports._errnoException (util.js:870:11)
at FSWatcher.start (fs.js:1234:19)
at Object.fs.watch (fs.js:1262:11)
at createFsWatchInstance (/home/flow/angular-pro-template/node_modules/gulp-watch/node_modules/chokidar/lib/nodefs-handler.js:37:15)
at setFsWatchListener (/home/flow/angular-pro-template/node_modules/gulp-watch/node_modules/chokidar/lib/nodefs-handler.js:80:15)
at FSWatcher.NodeFsHandler._watchWithNodeFs (/home/flow/angular-pro-template/node_modules/gulp-watch/node_modules/chokidar/lib/nodefs-handler.js:228:14)
at FSWatcher.NodeFsHandler._handleDir (/home/flow/angular-pro-template/node_modules/gulp-watch/node_modules/chokidar/lib/nodefs-handler.js:407:19)
at FSWatcher.<anonymous> (/home/flow/angular-pro-template/node_modules/gulp-watch/node_modules/chokidar/lib/nodefs-handler.js:455:19)
at FSWatcher.<anonymous> (/home/flow/angular-pro-template/node_modules/gulp-watch/node_modules/chokidar/lib/nodefs-handler.js:460:16)
at FSReqWrap.oncomplete (fs.js:82:15)

最开始以为是自己的姿势不对,安装官方用例,怎么换姿势都不对,最后在一个外国大神的 github issues 评论里面找到了解决方案:

the reason for the error is there is a limit in the system for how many files can be watched by a user, using the following command in a terminal window we can simply increase the limit ..

1
echo fs.inotify.max_user_watches=582222 | sudo tee -a /etc/sysctl.conf && sudo sysctl -p