Search code examples
node.jsreactjslocalhostweb-frameworks

localhost:3000 refused to connect when using npm start


I am new to react and having a problem here. Whenever I try to run my react app using npm start, I am getting these errors

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

Error: ENOSPC: System limit for number of file watchers reached, watch '/home/nrj/Documents/react/counter-app/public/favicon.ico'
    at FSWatcher.<computed> (internal/fs/watchers.js:218:26)
    at Object.watch (fs.js:1582:34)
    at createFsWatchInstance (/home/nrj/Documents/react/counter-app/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:38:15)
    at setFsWatchListener (/home/nrj/Documents/react/counter-app/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:81:15)
    at FSWatcher.NodeFsHandler._watchWithNodeFs (/home/nrj/Documents/react/counter-app/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:233:14)
    at FSWatcher.NodeFsHandler._handleFile (/home/nrj/Documents/react/counter-app/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:262:21)
    at FSWatcher.<anonymous> (/home/nrj/Documents/react/counter-app/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:495:21)
    at FSReqCallback.oncomplete (fs.js:193:5)
Emitted 'error' event on FSWatcher instance at:
    at FSWatcher._handleError (/home/nrj/Documents/react/counter-app/node_modules/webpack-dev-server/node_modules/chokidar/index.js:260:10)
    at createFsWatchInstance (/home/nrj/Documents/react/counter-app/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:40:5)
    at setFsWatchListener (/home/nrj/Documents/react/counter-app/node_modules/webpack-dev-server/node_modules/chokidar/lib/nodefs-handler.js:81:15)
    [... lines matching original stack trace ...]
    at FSReqCallback.oncomplete (fs.js:193:5) {
  errno: -28,
  syscall: 'watch',
  code: 'ENOSPC',
  path: '/home/nrj/Documents/react/counter-app/public/favicon.ico',
  filename: '/home/nrj/Documents/react/counter-app/public/favicon.ico'
}
npm ERR! code ELIFECYCLE
npm ERR! errno 1
npm ERR! counter-app@0.1.0 start: `react-scripts start`
npm ERR! Exit status 1
npm ERR! 
npm ERR! Failed at the counter-app@0.1.0 start script.
npm ERR! This is probably not a problem with npm. There is likely additional logging output above.

npm ERR! A complete log of this run can be found in:
npm ERR!     /home/nrj/.npm/_logs/2021-07-29T09_59_36_829Z-debug.log

I saw some solutions like updating node.js, deleting node_modules and running npm install, but they didn't work for me.


Solution

  • If you are running on Linux, it looks like you are exhausting the watchers limit

    try following the instructions here: https://stackoverflow.com/a/55411444/2799454