Movatterモバイル変換


[0]ホーム

URL:


Skip to content
DEV Community
Log in Create account

DEV Community

Peter Thaleikis 🍪
Peter Thaleikis 🍪

Posted on • Originally published atpeterthaleikis.com on

     

How to fix "throw er; // Unhandled 'error' event"?

Some errors are easy and simple. Quick fixes you get resolved in minutes. Others aren't and you got to dig in for much longer than you would like to. This was one of these for me. To make it a bit easier for other developers I'm sharing my solution here.

This problem seems to affect especially Linux users like myself. I can't confirm this for sure as I run only Linux 🐧️ On myelementary the issue usually comes up when I try to run npm/yarn commands which are supposed to watch file changes (e.g. CSS/SCSS or JavaScript files). The relateddev- andprod-commands work fine. It's only affectingwatch-command and appears to be linked to a file-system incompatibility when watching file changes.

This particular case problem arises while using my swiss armyknife build toolLaravel Mix on a project. When runningnpm run watch (actuallyyarn watch) I get this error messageafter the compile step is finish:

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

The line number depends on the exact libraries used in the project, but theevents.js file is usually part of it.

If supported,watch-poll often resolves the issue. But some libraries, like my starter for eleventy (this blog), aren't supporting poll and I needed to resort to a different approach. After spending some time researching and trying I've found a solution which works for now. I remove thenode_modules-folder (rm -rf node_modules) and force-clear the NPM cache (npm cache clear --force) before reinstalling the node dependencies. Summarized in the following steps:

rm -rf node_modulesrm package-lock.json yarn.locknpm cache clear --forcenpm install

Please note: This removes also the lock-file. Thereby updating your project, make sure to test everything before you push the changes to production 🙏️

Update #1: Solution: Stop all other "watch"-processes

If you have a number of node processes running this might be part of your issue. I've noticed the problem coming up more often if I've got a number of watch processes (for other projects) running. After stopping these and clearing the files as described above the issues was resolved.

Update #2 (2020-03-04): Error: ENOSPC: System limit for number of file watchers reached, watch 'src/assets'

With a recent update of my dependencies, I've noticed a new, better understandable wording for the known error. This points you much faster in the right direction. Again, I've been able to resolve the issue using the approach mentioned above.

Update #3 (2020-04-23): Increase allowed file handles

By chance I stumbled across a solution to increase the number of allowed file handles. This actually came with my recent trail of Microsoft Studio Code for Linux. It thrown a familiar sounding error:

Visual Studio Code is unable to watch for file changes in this large workspace (error ENOSPC)

Microsoft recommended the following to increase the number of allowed file handles. You can do by updating your/etc/sysctl.conf file. The detail steps are lined outhere.

Top comments(0)

Subscribe
pic
Create template

Templates let you quickly answer FAQs or store snippets for re-use.

Dismiss

Are you sure you want to hide this comment? It will become hidden in your post, but will still be visible via the comment'spermalink.

For further actions, you may consider blocking this person and/orreporting abuse

Developer and indie maker. Building little projects in the hope someone likes them :D
  • Location
    Wellington, NZ
  • Work
    CEO (chief everything officer) at bring your own ideas Ltd.
  • Joined

More fromPeter Thaleikis 🍪

DEV Community

We're a place where coders share, stay up-to-date and grow their careers.

Log in Create account

[8]ページ先頭

©2009-2025 Movatter.jp