<h1 dir="auto">Bug report</h1>
<p dir="auto">When closing a watching compiler programmatically, the node process crashes.</p>




<p dir="auto"><strong>What is the current behavior?</strong><br>
Getting the following crash in several repositories on our Mac CIs:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="Assertion failed: (0), function uv_close, file ../deps/uv/src/unix/core.c, line 187.
error Command failed with signal &quot;SIGABRT&quot;."><pre class="notranslate"><code class="notranslate">Assertion failed: (0), function uv_close, file ../deps/uv/src/unix/core.c, line 187.
error Command failed with signal "SIGABRT".
</code></pre></div>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>
<ul dir="auto">
<li>clone repo: <a href="https://github.com/AviVahl/lodash-es-webpack4">https://github.com/AviVahl/lodash-es-webpack4</a></li>
<li><code class="notranslate">yarn</code></li>
<li>paste the following to <code class="notranslate">a.js</code>:</li>
</ul>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="const webpack = require('webpack');
const compiler = webpack({ mode: 'development' });

function createWatcher() {
    const watcher = compiler.watch({}, () =&gt; {
        console.log('watching');
        setTimeout(() =&gt; {
            watcher.close(() =&gt; {
                console.log('closed watcher');
                createWatcher();
            });
        }, 1000);
    });
}

createWatcher();"><pre class="notranslate"><span class="pl-k">const</span> <span class="pl-s1">webpack</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'webpack'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-k">const</span> <span class="pl-s1">compiler</span> <span class="pl-c1">=</span> <span class="pl-s1">webpack</span><span class="pl-kos">(</span><span class="pl-kos">{</span> <span class="pl-c1">mode</span>: <span class="pl-s">'development'</span> <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>

<span class="pl-k">function</span> <span class="pl-en">createWatcher</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-kos">{</span>
    <span class="pl-k">const</span> <span class="pl-s1">watcher</span> <span class="pl-c1">=</span> <span class="pl-s1">compiler</span><span class="pl-kos">.</span><span class="pl-en">watch</span><span class="pl-kos">(</span><span class="pl-kos">{</span><span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
        <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'watching'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-en">setTimeout</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
            <span class="pl-s1">watcher</span><span class="pl-kos">.</span><span class="pl-en">close</span><span class="pl-kos">(</span><span class="pl-kos">(</span><span class="pl-kos">)</span> <span class="pl-c1">=&gt;</span> <span class="pl-kos">{</span>
                <span class="pl-smi">console</span><span class="pl-kos">.</span><span class="pl-en">log</span><span class="pl-kos">(</span><span class="pl-s">'closed watcher'</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
                <span class="pl-en">createWatcher</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
            <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
        <span class="pl-kos">}</span><span class="pl-kos">,</span> <span class="pl-c1">1000</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
    <span class="pl-kos">}</span><span class="pl-kos">)</span><span class="pl-kos">;</span>
<span class="pl-kos">}</span>

<span class="pl-en">createWatcher</span><span class="pl-kos">(</span><span class="pl-kos">)</span><span class="pl-kos">;</span></pre></div>
<ul dir="auto">
<li><code class="notranslate">node a.js</code></li>
</ul>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
(for the above code) watch -&gt; wait for 1 sec -&gt; close watcher -&gt; rewatch and repeat process.</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  4.41.2<br>
Node.js version: 13.2.0<br>
Operating System: Mac 10.12.6</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/sokra/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/sokra">@sokra</a> maybe this is because <code class="notranslate">watchpack</code> is using old <code class="notranslate">chokidar</code> with outdated <code class="notranslate">fsevents</code>? :/</p>
<p dir="auto"><strong>Do you want to request a <em>feature</em> or report a <em>bug</em>?</strong><br>
Bug</p>
<p dir="auto"><strong>What is the current behavior?</strong><br>
It's impossible to perform a rule based on <code class="notranslate">resourceQuery</code> condition if a module has no query at all. That module won't pass directly.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
I have this case where there are resources of the same extension that some are loaded in a certain way an some in another. I can reach it using resource queries.</p>
<p dir="auto">So I can write some config like this:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="{
  module: {
    rules: {
      {
        test: /\.ext$/i,
        resourceQuery: {
          exclude: /\?another/i,
        },
        loader: 'normal-loader'
      },
      {
        test: /\.ext$/i,
        resourceQuery: /\?another/i,
        loader: 'another-loader'
      }
    }
  }
}"><pre class="notranslate"><span class="pl-kos">{</span>
  module: <span class="pl-kos">{</span>
    rules: <span class="pl-kos">{</span>
      <span class="pl-kos">{</span>
        <span class="pl-c1">test</span>: <span class="pl-pds"><span class="pl-c1">/</span><span class="pl-cce">\.</span>ext<span class="pl-cce">$</span><span class="pl-c1">/</span>i</span><span class="pl-kos">,</span>
        <span class="pl-c1">resourceQuery</span>: <span class="pl-kos">{</span>
          <span class="pl-c1">exclude</span>: <span class="pl-pds"><span class="pl-c1">/</span><span class="pl-cce">\?</span>another<span class="pl-c1">/</span>i</span><span class="pl-kos">,</span>
        <span class="pl-kos">}</span><span class="pl-kos">,</span>
        <span class="pl-c1">loader</span>: <span class="pl-s">'normal-loader'</span>
      <span class="pl-kos">}</span><span class="pl-kos">,</span>
      <span class="pl-kos">{</span>
        <span class="pl-c1">test</span>: <span class="pl-pds"><span class="pl-c1">/</span><span class="pl-cce">\.</span>ext<span class="pl-cce">$</span><span class="pl-c1">/</span>i</span><span class="pl-kos">,</span>
        <span class="pl-c1">resourceQuery</span>: <span class="pl-pds"><span class="pl-c1">/</span><span class="pl-cce">\?</span>another<span class="pl-c1">/</span>i</span><span class="pl-kos">,</span>
        <span class="pl-c1">loader</span>: <span class="pl-s">'another-loader'</span>
      <span class="pl-kos">}</span>
    <span class="pl-kos">}</span>
  <span class="pl-kos">}</span>
<span class="pl-kos">}</span></pre></div>
<p dir="auto">So I want that <code class="notranslate">.ext</code> files get loaded with <code class="notranslate">normal-loader</code>. <em>Except</em> the ones with <code class="notranslate">?another</code> query, these will load with <code class="notranslate">another-loader</code>.</p>
<p dir="auto">But here's the result:</p>
<ul dir="auto">
<li><code class="notranslate">path/to/module.ext?another</code>: loaded with <code class="notranslate">another-loader</code></li>
<li><code class="notranslate">path/to/module.ext?asdfg</code>: loaded with <code class="notranslate">normal-loader</code></li>
<li><code class="notranslate">path/to/module.ext</code>: <strong>none</strong>, but we were naturally expecting <code class="notranslate">normal-loader</code></li>
</ul>
<p dir="auto">I guess there's a problem with the logic around here:<br>
<a href="https://github.com/webpack/webpack/blob/v2.2.0-rc.0/lib/RuleSet.js#L361">https://github.com/webpack/webpack/blob/v2.2.0-rc.0/lib/RuleSet.js#L361</a><br>
It's skipping the condition and rejecting directly if <code class="notranslate">resourceQuery</code> is empty and there's a condition.</p>
<p dir="auto"><strong>What is the expected behavior?</strong><br>
It must be able to test a <code class="notranslate">resourceQuery</code> condition in an empty query.</p>
<p dir="auto"><strong>Please mention other relevant information such as the browser version, Node.js version, Operating System and programming language.</strong><br>
Node.js: v7.2.1<br>
Webpack: v2.2.0-rc.0</p>