<?xml version="1.0" encoding="UTF-8"?><rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>Unhandled errors &#8211; CodingQuerry</title>
	<atom:link href="http://localhost/category/unhandled-errors/feed/?simply_static_page=42" rel="self" type="application/rss+xml" />
	<link>/</link>
	<description></description>
	<lastBuildDate>Thu, 20 Jun 2024 12:07:40 +0000</lastBuildDate>
	<language>en-US</language>
	<sy:updatePeriod>
	hourly	</sy:updatePeriod>
	<sy:updateFrequency>
	1	</sy:updateFrequency>
	<generator>https://wordpress.org/?v=6.5.4</generator>
	<item>
		<title>How to Fix &#8220;throw er; // Unhandled &#8216;error&#8217; event&#8221;?</title>
		<link>/how-to-fix-throw-er-unhandled-error-event/</link>
					<comments>/how-to-fix-throw-er-unhandled-error-event/#respond</comments>
		
		<dc:creator><![CDATA[admin]]></dc:creator>
		<pubDate>Thu, 20 Jun 2024 12:07:40 +0000</pubDate>
				<category><![CDATA[Unhandled errors]]></category>
		<guid isPermaLink="false">/?p=6</guid>

					<description><![CDATA[Some errors are easy and simple. Quick fixes you get resolved in minutes. Others aren&#8217;t and you got to dig in for much longer than you would like to. This was one of these for me. I&#8217;m sharing my solution here to make it a bit easier for other developers. This problem seems to affect]]></description>
										<content:encoded><![CDATA[<p>Some errors are easy and simple. Quick fixes you get resolved in minutes. Others aren&#8217;t and you got to dig in for much longer than you would like to. This was one of these for me. I&#8217;m sharing my solution here to make it a bit easier for other developers.</p>
<p>This problem seems to affect especially Linux users like myself. I can&#8217;t confirm this for sure as I run only Linux <img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f427.png" alt="🐧" class="wp-smiley" style="height: 1em; max-height: 1em;" /> 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 <code>dev</code>&#8211; and <code>prod</code>-commands work fine. It&#8217;s only affecting <code>watch</code>-command and appears to be linked to a file-system incompatibility when watching file changes.</p>
<p>&nbsp;</p>
<p>This particular case problem arises while using my swiss armyknife build tool Laravel Mix on a project. When running <code>npm run watch</code> (actually <code>yarn watch</code>) I get this error message <em>after</em> the compile step is finish:</p>
<pre class=" language-javascript"><code class=" language-javascript">events<span class="token punctuation">.</span>js<span class="token punctuation">:</span><span class="token number">292</span>
      <span class="token keyword">throw</span> er<span class="token punctuation">;</span> <span class="token comment">// Unhandled 'error' event</span>
      <span class="token operator">^</span>
</code></pre>
<p>The line number depends on the exact libraries used in the project, but the <code>events.js</code> filename or <code>throw er; // unhandled 'error' event</code> are usually part of the error.</p>
<p>If supported, <code>watch-poll</code> often resolves the issue. But some libraries, like my starter for eleventy (this blog), aren&#8217;t supporting poll and I needed to resort to a different approach. After spending some time researching and trying I&#8217;ve found a solution which works for now. I remove the <code>node_modules</code>-folder (<code>rm -rf node_modules</code>) and force-clear the NPM cache (<code>npm cache clear --force</code>) before reinstalling the node dependencies. Summarized in the following steps:</p>
<p>&nbsp;</p>
<pre class=" language-bash"><code class=" language-bash">rm -rf node_modules
rm package-lock.json yarn.lock
npm cache clear --force
npm install
</code></pre>
<p>Please note: This removes also the lock-file. Thereby updating your project, make sure to test everything before you push the changes to production <img src="https://s.w.org/images/core/emoji/15.0.3/72x72/1f64f.png" alt="🙏" class="wp-smiley" style="height: 1em; max-height: 1em;" /></p>
<h2>Update #1: Solution: Stop all other &#8220;watch&#8221;-processes</h2>
<p>If you have a number of node processes running this might be part of your issue. I&#8217;ve noticed the problem coming up more often if I&#8217;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.</p>
<p>&nbsp;</p>
<h2>Update #2 (2020-03-04): Error: ENOSPC: System limit for number of file watchers reached, watch &#8216;src/assets&#8217;</h2>
<p>With a recent update of my dependencies, I&#8217;ve noticed a new, better understandable wording for the known error. This points you much faster in the right direction. Again, I&#8217;ve been able to resolve the issue using the approach mentioned above.</p>
<h2>Update #3 (2020-04-23): Increase allowed file handles</h2>
<p>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:</p>
<pre><code>Visual Studio Code is unable to watch for file changes in this large workspace (error ENOSPC)
</code></pre>
<p>Microsoft recommended the following to increase the number of allowed file handles. You can do by updating your <code>/etc/sysctl.conf</code> file. The detail steps are lined out here.</p>
<p>&nbsp;</p>
<h2>Update #4: Do you prefer a video?</h2>
<p>More a video guy? Someone also made a video based on the content of article:</p>
<p><iframe src="https://www.youtube.com/embed/_GG9jgLgBXk" width="560" height="315" frameborder="0" allowfullscreen="allowfullscreen" data-mce-fragment="1"></iframe></p>
<h2>Update #5:</h2>
<p>This might also come with a blocked port an app is try to listen to. In this case your error message might look like this:</p>
<pre><code>node:events:505 throw er; // unhandled 'error' event ^ error: listen eaddrinuse: address already in use :::5000
</code></pre>
<p>The port at the end, here <code>5000</code>, can vary.</p>
<p>If this looks like your problem, you might want to check what is listening on the port in question. Simply open the port with port, e.g. <code>localhost:5000</code>, in your browser. After turning of the application in question or changing your port this problem should be resolved.</p>
<h2>By the way</h2>
<p>I love the web and building stuff! The web still has lots amazing open-source libraries and <i>actually</i> innovative side-projects. Once in a while, I share these <b>awesome web-findings</b> via email. If this sounds like something you are into, subscribe below:</p>
]]></content:encoded>
					
					<wfw:commentRss>/how-to-fix-throw-er-unhandled-error-event/feed/</wfw:commentRss>
			<slash:comments>0</slash:comments>
		
		
			</item>
	</channel>
</rss>
