by Peter Thaleikis
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. I'm sharing my solution here to make it a bit easier for other developers.
This problem seems to affect especially Linux users like myself. I can't confirm this for sure as I run only Linux 🐧️ On my
elementary
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 problem affects all frameworks from VueJS, to React and Angular. The related
dev
- and
prod
-commands work fine. It's only affecting
watch
-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 tool Laravel Mix on a project. When running
npm run watch
(actually
yarn watch
) I get this error message
after
the compile step is finish:
events.js:292
throw er; // Unhandled 'error' event
The line number depends on the exact libraries used in the project, but the
events.js
filename or
throw er; // unhandled 'error' event
are usually part of the error.
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 the
node_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_modules