<p dir="auto">I'm having an issue with webpack where if I stop watching and restart, it will build just fine, but if I edit a file and save it, the incremental build fails with this error:</p>
<p dir="auto"><strong>Uncaught TypeError: Cannot read property 'call' of undefined</strong></p>
<p dir="auto">Hunting it down there's a module that does not get included in the incremental change build. Best guess is the path followed to re-make the bundle file is not being followed correctly. Upon re-running (stop and start), the missing module is included.</p>
<p dir="auto">webpack.config.js (module names changed to protect the innocent):</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var webpack = require(&quot;webpack&quot;),
    path = require('path')
    ;

module.exports = {
  entry: {
    Entry1: &quot;./app/Entry1.js&quot;,
    Entry2: &quot;./app/Entry2.js&quot;,
    Entry3: &quot;./app/Entry3.js&quot;,
    Entry4: &quot;./app/Entry4.js&quot;,
    Entry5: &quot;./app/Entry5.js&quot;,
    Entry6: &quot;./app/Entry6.js&quot;,
    Entry7: &quot;./app/Entry7.js&quot;,
    Entry8: &quot;./app/Entry8.js&quot;,
  },
  output: {
    path: path.join(__dirname, &quot;public/js&quot;),
    filename: &quot;[name].bundle.js&quot;,
    chunkFilename: &quot;[id].chunk.js&quot;
  },
  module: {
    loaders: [
      {test: /\.js$/, loader: 'jsx-loader'}
    ]
  },
    plugins: [
        new webpack.optimize.CommonsChunkPlugin(&quot;shared.js&quot;)
    ]
};"><pre class="notranslate"><span class="pl-k">var</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-s1">path</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">(</span><span class="pl-s">'path'</span><span class="pl-kos">)</span>
    <span class="pl-kos">;</span>

<span class="pl-smi">module</span><span class="pl-kos">.</span><span class="pl-c1">exports</span> <span class="pl-c1">=</span> <span class="pl-kos">{</span>
  <span class="pl-c1">entry</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">Entry1</span>: <span class="pl-s">"./app/Entry1.js"</span><span class="pl-kos">,</span>
    <span class="pl-c1">Entry2</span>: <span class="pl-s">"./app/Entry2.js"</span><span class="pl-kos">,</span>
    <span class="pl-c1">Entry3</span>: <span class="pl-s">"./app/Entry3.js"</span><span class="pl-kos">,</span>
    <span class="pl-c1">Entry4</span>: <span class="pl-s">"./app/Entry4.js"</span><span class="pl-kos">,</span>
    <span class="pl-c1">Entry5</span>: <span class="pl-s">"./app/Entry5.js"</span><span class="pl-kos">,</span>
    <span class="pl-c1">Entry6</span>: <span class="pl-s">"./app/Entry6.js"</span><span class="pl-kos">,</span>
    <span class="pl-c1">Entry7</span>: <span class="pl-s">"./app/Entry7.js"</span><span class="pl-kos">,</span>
    <span class="pl-c1">Entry8</span>: <span class="pl-s">"./app/Entry8.js"</span><span class="pl-kos">,</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-c1">output</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">path</span>: <span class="pl-s1">path</span><span class="pl-kos">.</span><span class="pl-en">join</span><span class="pl-kos">(</span><span class="pl-s1">__dirname</span><span class="pl-kos">,</span> <span class="pl-s">"public/js"</span><span class="pl-kos">)</span><span class="pl-kos">,</span>
    <span class="pl-c1">filename</span>: <span class="pl-s">"[name].bundle.js"</span><span class="pl-kos">,</span>
    <span class="pl-c1">chunkFilename</span>: <span class="pl-s">"[id].chunk.js"</span>
  <span class="pl-kos">}</span><span class="pl-kos">,</span>
  <span class="pl-c1">module</span>: <span class="pl-kos">{</span>
    <span class="pl-c1">loaders</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>js<span class="pl-cce">$</span><span class="pl-c1">/</span></span><span class="pl-kos">,</span> <span class="pl-c1">loader</span>: <span class="pl-s">'jsx-loader'</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">plugins</span>: <span class="pl-kos">[</span>
        <span class="pl-k">new</span> <span class="pl-s1">webpack</span><span class="pl-kos">.</span><span class="pl-c1">optimize</span><span class="pl-kos">.</span><span class="pl-c1">CommonsChunkPlugin</span><span class="pl-kos">(</span><span class="pl-s">"shared.js"</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">I’ve run into a fairly strange, fairly specific problem when running webpack in watch mode on OS X. When using <code class="notranslate">require.context</code> in the presence of a module with a lot of dependencies in <code class="notranslate">node_modules</code> that was symlinked using <code class="notranslate">npm link</code>, webpack seems to open a <em>lot</em> of file descriptors, very quickly leading to a rapid stream of dozens of errors per second coming from OS X’s FSEvents framework:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="2016-04-18 11:21 node[34856] (FSEvents.framework) FSEventStreamRelease(): failed assertion 'streamRef != NULL'
2016-04-18 11:21 node[34856] (FSEvents.framework) FSEventStreamRelease(): failed assertion 'streamRef != NULL'
2016-04-18 11:21 node[34856] (FSEvents.framework) FSEventStreamCreate: _FSEventStreamCreate: ERROR: could not open kqueue
2016-04-18 11:21 node[34856] (FSEvents.framework) FSEventStreamScheduleWithRunLoop(): failed assertion 'streamRef != NULL'
2016-04-18 11:21 node[34856] (FSEvents.framework) FSEventStreamStart(): failed assertion 'streamRef != NULL'"><pre class="notranslate"><code class="notranslate">2016-04-18 11:21 node[34856] (FSEvents.framework) FSEventStreamRelease(): failed assertion 'streamRef != NULL'
2016-04-18 11:21 node[34856] (FSEvents.framework) FSEventStreamRelease(): failed assertion 'streamRef != NULL'
2016-04-18 11:21 node[34856] (FSEvents.framework) FSEventStreamCreate: _FSEventStreamCreate: ERROR: could not open kqueue
2016-04-18 11:21 node[34856] (FSEvents.framework) FSEventStreamScheduleWithRunLoop(): failed assertion 'streamRef != NULL'
2016-04-18 11:21 node[34856] (FSEvents.framework) FSEventStreamStart(): failed assertion 'streamRef != NULL'
</code></pre></div>
<p dir="auto">This issue is similar to <a class="issue-link js-issue-link" data-error-text="Failed to load title" data-id="121615819" data-permission-text="Title is private" data-url="https://github.com/webpack/webpack/issues/1743" data-hovercard-type="issue" data-hovercard-url="/webpack/webpack/issues/1743/hovercard" href="https://github.com/webpack/webpack/issues/1743">#1743</a>, but I am not sure that it is actually the same, since that appears to be resolved with a chokidar fix, but I am using the latest version of chokidar and still get the error.</p>
<h1 dir="auto">Steps to reproduce</h1>
<p dir="auto">Since this is such a specific problem, I’ve managed to reduce it to a pretty tiny, reproducible example, which you can find at <a href="https://github.com/lexi-lambda/webpack-fsevents-bug">lexi-lambda/webpack-fsevents-bug</a>. Here’s some information about my environment as well:</p>
<blockquote>
<p dir="auto"><strong>operating system</strong>: OS X 10.11.3<br>
<strong>node version</strong>: v5.10.1<br>
<strong>npm version</strong>: 3.8.3</p>
</blockquote>
<p dir="auto">Here’s how to reproduce the issue:</p>
<ol dir="auto">
<li>Clone <a href="https://github.com/lexi-lambda/webpack-fsevents-bug">https://github.com/lexi-lambda/webpack-fsevents-bug</a> somewhere.</li>
<li>Enter the <code class="notranslate">linking-test</code> directory and run <code class="notranslate">npm install</code>, then <code class="notranslate">npm link</code>.</li>
<li>Enter the <code class="notranslate">main</code> directory and run <code class="notranslate">npm install</code>, then <code class="notranslate">npm link linking-test</code>.</li>
<li>Run <code class="notranslate">npm run watch</code>.</li>
<li>After a few seconds, you should start seeing the FSEvents errors.</li>
</ol>
<h1 dir="auto">More details</h1>
<p dir="auto">The issue seems to specifically be related to how running webpack in watch mode interacts with <code class="notranslate">require.context</code>. If you look in <a href="https://github.com/lexi-lambda/webpack-fsevents-bug/blob/master/main/src/index.js">the single module in the whole project</a>, you’ll see the following two lines:</p>
<div class="highlight highlight-source-js notranslate position-relative overflow-auto" dir="auto" data-snippet-clipboard-copy-content="var context = require.context('..', false, /config\.json$/);
console.log(context.keys());"><pre class="notranslate"><span class="pl-k">var</span> <span class="pl-s1">context</span> <span class="pl-c1">=</span> <span class="pl-en">require</span><span class="pl-kos">.</span><span class="pl-en">context</span><span class="pl-kos">(</span><span class="pl-s">'..'</span><span class="pl-kos">,</span> <span class="pl-c1">false</span><span class="pl-kos">,</span> <span class="pl-pds"><span class="pl-c1">/</span>config<span class="pl-cce">\.</span>json<span class="pl-cce">$</span><span class="pl-c1">/</span></span><span class="pl-kos">)</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-s1">context</span><span class="pl-kos">.</span><span class="pl-en">keys</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">I’ve explicitly passed <code class="notranslate">false</code> to <code class="notranslate">require.context</code>, but for some reason the placement of the linked package in the <code class="notranslate">node_modules</code> subdirectory <em>clearly</em> affects how webpack handles this context. The error does not occur without the custom context.</p>
<p dir="auto">I have no idea if this has anything to do with a symlinked module specifically, and it’s certainly not that simple, because it doesn’t happen if the symlinked module does not have very many dependencies. However, with a lot of dependencies, like the ones I’ve included in my sample repo, it consistently fails. It might just be caused by having a lot of files/subdirectories and have nothing to do with the symlinking—I don’t know.</p>
<p dir="auto">Either way, this is a pretty hard failure that is consistently reproducible, even on different machines, and I’ve been running into it repeatedly with a particular project I’m working on. Thank you for making webpack, it’s a wonderful tool! And let me know if there’s any more information I can provide to help.</p>