今天想运行一下一个 React 项目,昨天还好好的但是今天却报如下错误:

Starting the development server...

events.js:174
      throw er; // Unhandled 'error' event
      ^

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/king/PBK_Data/test/helloreact/public'
    at FSWatcher.start (internal/fs/watchers.js:165:26)
    at Object.watch (fs.js:1258:11)
    at createFsWatchInstance (/home/king/PBK_Data/test/helloreact/node_modules/chokidar/lib/nodefs-handler.js:38:15)
    at setFsWatchListener (/home/king/PBK_Data/test/helloreact/node_modules/chokidar/lib/nodefs-handler.js:81:15)
    at FSWatcher.NodeFsHandler._watchWithNodeFs (/home/king/PBK_Data/test/helloreact/node_modules/chokidar/lib/nodefs-handler.js:233:14)
    at FSWatcher.NodeFsHandler._handleDir (/home/king/PBK_Data/test/helloreact/node_modules/chokidar/lib/nodefs-handler.js:429:19)
    at FSWatcher.<anonymous> (/home/king/PBK_Data/test/helloreact/node_modules/chokidar/lib/nodefs-handler.js:477:19)
    at FSWatcher.<anonymous> (/home/king/PBK_Data/test/helloreact/node_modules/chokidar/lib/nodefs-handler.js:482:16)
    at FSReqWrap.oncomplete (fs.js:154:5)
Emitted 'error' event at:
    at FSWatcher._handleError (/home/king/PBK_Data/test/helloreact/node_modules/chokidar/index.js:260:10)
    at createFsWatchInstance (/home/king/PBK_Data/test/helloreact/node_modules/chokidar/lib/nodefs-handler.js:40:5)
    at setFsWatchListener (/home/king/PBK_Data/test/helloreact/node_modules/chokidar/lib/nodefs-handler.js:81:15)
    [... lines matching original stack trace ...]
    at FSReqWrap.oncomplete (fs.js:154:5)
error Command failed with exit code 1.

原来在 fedorac,entos,ubuntu 等系统中,由于 gulp serve 跟踪项目的文件数有限制,必须要设置一下,解除设置才可以继续跟踪。还有可能是因为 gulp 的 watch 需要监听很多文件的改动,但是 fedora,ubuntu 系统的文件句柄其实是有限制的,因此可以使用下面的命令解除

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