How to Fix “throw er; // Unhandled ‘error’ event”?

Caroline Cah
Caroline Cah

Have you ever been to this error when running your build? I came across this once. When I was trying to run localhost in react it gave me this. The error you're seeing seems to originate from the fsevents package, which is a native module used to watch filesystem changes on macOS. This package can sometimes cause issues, especially if you're not on a macOS system or when there are mismatches between native module versions and the Node.js version you're using.

      throw er; // Unhandled 'error' event

How can this be resolved? First try killing all node processes

sudo killall -9 node

Ensure Compatibility:

Make sure you're using a macOS system. fsevents is specifically for macOS.

Verify that you're using a compatible Node.js version with your project. For example, if you're using a newer version of node there might be a missmatch with your dependencies.

Reinstall Node Modules: Often, deleting the node_modules directory and reinstalling can solve many problems.

You can do this by:

bashCopy coderm -rf node_modules npm install

Update your Dependencies: Your issue might be caused by outdated packages. Try updating all your dependencies:

If you're using yarn:

bashCopy codeyarn upgrade

If it doesn’t help then it may be cache problem. You can remove it by below command.

yarn cache clean


npm cache clean --force


sudo npm cache clean --force
More posts