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

Premal Katigar
2 min readApr 2, 2020

--

Have you ever been to this error? I came across this once. When I was trying to run localhost in react it gave me this.

throw er; // Unhandled 'error' event

some errors are tricky that needs some more research and logic. It was one of them. I resolved this issue but it took 2 days.

sudo killall -9 node

Execute above command to kill all current processes and see if it will work or not.

npm install ws@3.3.2 --save-dev --save-exact

Try to install above npm package. It has resolved my issue.

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

npm cache clean --force or sudo npm cache clean --force

See it works or not. if not try to give permission to your all files. It might be a permission problem sometime that restrict to install packages.

sudo chown -R 1000:1000 "/home/prem/.npm"

Now try remove node_modules and install packages with npm i. If it will work the better then try to avoid ENOSPC by below command:

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

Above code with increase user_watches and avoid ENOSPC.

Source of Post: http://www.premalkatigar.com/javascript/how-to-fix-throw-er-unhandled-error-event/

Happy Coding!

--

--

Premal Katigar

Fullstack Developer | Technology Fanatic | Problem Player | Thoughtful | https://premalkatigar.com