<h1 dir="auto">Bug report</h1>
<p dir="auto">We have a multi-page website that uses Webpack v4. Some pages have entry files. All pages have UI that needs JS to run.</p>
<p dir="auto">In the past, we have had an entry that acts as a global JS initializer. This contains code for the site navigation, modernizr, and other global utilities. This is site level, consider it page agnostic code.</p>
<p dir="auto">Additionally, we have entries for some pages that have additional JS driven UI. The entry files are not mapped to all pages though, so some pages will not have an entry.</p>
<p dir="auto">When we build our &lt;script&gt; tags, we used to do something like this:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="&lt;script src='global.bundle.js' /&gt;
&lt;script src='mypage.bundle.js' /&gt;"><pre class="notranslate"><code class="notranslate">&lt;script src='global.bundle.js' /&gt;
&lt;script src='mypage.bundle.js' /&gt;
</code></pre></div>




<p dir="auto">Stack Overflow discussion here: <a href="https://stackoverflow.com/questions/54795391/webpack-v4-with-multiple-entries-on-a-single-page-chunks-are-duplicated-unneces?noredirect=1" rel="nofollow">https://stackoverflow.com/questions/54795391/webpack-v4-with-multiple-entries-on-a-single-page-chunks-are-duplicated-unneces?noredirect=1</a></p>
<p dir="auto"><strong>What is the current behavior?</strong><br>
We are encountering a bug in Webpack v4 where chunks that are shared between <strong>global</strong> and <strong>mypage</strong> are redundantly included in each bundle. Webpack is not aware that these files exist on the same page together, so it treats them as if they do not have access to eachother. We have been unable to locate a configuration that creates this link.</p>
<p dir="auto">We need this link because we cannot make an entry for each page that imports an init file from <strong>global.js</strong>, and even if we could, it would cause unnecessary overhead. A clear separation of concerns is ideal, where global actions and page-specific actions live in different files and do not reference each other.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
Create a config with more than one entry, and include both in the same page. Add some imports to files that are used on both entries. Analyze the bundle and you'll find the same chunks in both files.</p>






<p dir="auto">Example config file here: <a href="https://gist.github.com/lostPixels/fef3f0cc4a3e99bf526249c605c2096f">https://gist.github.com/lostPixels/fef3f0cc4a3e99bf526249c605c2096f</a></p>
<p dir="auto"><strong>What is the expected behavior?</strong><br>
Webpack should optimize the entries to include only one chunk, and share it across multiple entries that live together in one HTML document. The config should offer a way to describe these connections, and not assume that a page can only contain one entry file.</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  4.28.4<br>
Node.js version: 9.3.0<br>
Operating System: OSX<br>
Additional tools: Salesforce Commerce Cloud Ecommerce platform</p>
<p dir="auto"><a class="user-mention notranslate" data-hovercard-type="user" data-hovercard-url="/users/niieani/hovercard" data-octo-click="hovercard-link-click" data-octo-dimensions="link_type:self" href="https://github.com/niieani">@niieani</a></p>
<ul class="contains-task-list">
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> <code class="notranslate">afterAll</code> and <code class="notranslate">beforeAll</code> are called even if the test cases are skipped</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> running test suites with all test cases skipped takes very long time</p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> <code class="notranslate">yarn test:integration -t runtime-chunk --watch</code> on node.js v10.0.0 (windows) causes this:</p>
</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[6904]: src\fs_event_wrap.cc:90: Assertion `wrap != nullptr' failed.
 1: node::DecodeWrite
 2: node::DecodeWrite
 3: node::Start
 4: v8::internal::interpreter::BytecodeDecoder::Decode
 5: v8::internal::RegExpImpl::Exec
 6: v8::internal::RegExpImpl::Exec
 7: v8::internal::Object::ToInt32
 8: v8::internal::Object::GetProperty
 9: v8::internal::NativesCollection&lt;0&gt;::GetScriptsSource
10: v8::internal::NativesCollection&lt;0&gt;::GetScriptsSource
11: 0000022CAD704281
error Command failed with exit code 134."><pre class="notranslate"><code class="notranslate">[6904]: src\fs_event_wrap.cc:90: Assertion `wrap != nullptr' failed.
 1: node::DecodeWrite
 2: node::DecodeWrite
 3: node::Start
 4: v8::internal::interpreter::BytecodeDecoder::Decode
 5: v8::internal::RegExpImpl::Exec
 6: v8::internal::RegExpImpl::Exec
 7: v8::internal::Object::ToInt32
 8: v8::internal::Object::GetProperty
 9: v8::internal::NativesCollection&lt;0&gt;::GetScriptsSource
10: v8::internal::NativesCollection&lt;0&gt;::GetScriptsSource
11: 0000022CAD704281
error Command failed with exit code 134.
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> The WatchDetection suite cause jest crashing in watch mode</li>
</ul>
<p dir="auto">Investigation: When running jest in watch mode and running the WatchDetection test, sane emits EPERM errors on windows. <code class="notranslate">sane</code> doesn't seem to check the ignore list when directories are added (<a href="https://github.com/amasad/sane/blob/master/src/node_watcher.js#L310">https://github.com/amasad/sane/blob/master/src/node_watcher.js#L310</a>) and reading the stats from a removed file seem to cause an EPERM error here (<a href="https://github.com/amasad/sane/blob/master/src/node_watcher.js#L306">https://github.com/amasad/sane/blob/master/src/node_watcher.js#L306</a>). I believe it's an sane issue. Although it would also be great if watcher errors would be catched (via <code class="notranslate">watcher.on("error")</code>) in jest-haste-map.</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, lstat 'D:\Repos\webpack\test\fixtures\temp-1600\file2.js'
error Command failed with exit code 1."><pre class="notranslate"><code class="notranslate">events.js:183
      throw er; // Unhandled 'error' event
      ^

Error: EPERM: operation not permitted, lstat 'D:\Repos\webpack\test\fixtures\temp-1600\file2.js'
error Command failed with exit code 1.
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> random error in watch mode, occurred only once</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="D:\Repos\webpack\node_modules\jest-runtime\build\index.js:581
    const wrapper = this._environment.runScript(transformedFile.script)[
                                                                       ^

TypeError: Cannot read property 'Object.&lt;anonymous&gt;' of null
    at Runtime._execModule (D:\Repos\webpack\node_modules\jest-runtime\build\index.js:581:72)
    at Runtime.requireModule (D:\Repos\webpack\node_modules\jest-runtime\build\index.js:365:14)
    at Runtime.requireModuleOrMock (D:\Repos\webpack\node_modules\jest-runtime\build\index.js:449:19)
    at readdir (D:\Repos\webpack\node_modules\readdirp\readdirp.js:55:25)
    at FSWatcher.&lt;anonymous&gt; (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:356:5)
    at FSWatcher.Object.&lt;anonymous&gt;.NodeFsHandler._handleDir (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:407:18)
    at FSWatcher.&lt;anonymous&gt; (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:456:19)
    at FSWatcher.&lt;anonymous&gt; (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:461:16)
    at D:\Repos\webpack\node_modules\graceful-fs\polyfills.js:287:18
    at FSReqWrap.oncomplete (fs.js:153:5)"><pre class="notranslate"><code class="notranslate">D:\Repos\webpack\node_modules\jest-runtime\build\index.js:581
    const wrapper = this._environment.runScript(transformedFile.script)[
                                                                       ^

TypeError: Cannot read property 'Object.&lt;anonymous&gt;' of null
    at Runtime._execModule (D:\Repos\webpack\node_modules\jest-runtime\build\index.js:581:72)
    at Runtime.requireModule (D:\Repos\webpack\node_modules\jest-runtime\build\index.js:365:14)
    at Runtime.requireModuleOrMock (D:\Repos\webpack\node_modules\jest-runtime\build\index.js:449:19)
    at readdir (D:\Repos\webpack\node_modules\readdirp\readdirp.js:55:25)
    at FSWatcher.&lt;anonymous&gt; (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:356:5)
    at FSWatcher.Object.&lt;anonymous&gt;.NodeFsHandler._handleDir (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:407:18)
    at FSWatcher.&lt;anonymous&gt; (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:456:19)
    at FSWatcher.&lt;anonymous&gt; (D:\Repos\webpack\node_modules\chokidar\lib\nodefs-handler.js:461:16)
    at D:\Repos\webpack\node_modules\graceful-fs\polyfills.js:287:18
    at FSReqWrap.oncomplete (fs.js:153:5)
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> CI is hanging</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="(node:2612) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'spies' of undefined
(node:2612) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2612) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code."><pre class="notranslate"><code class="notranslate">(node:2612) UnhandledPromiseRejectionWarning: TypeError: Cannot read property 'spies' of undefined
(node:2612) UnhandledPromiseRejectionWarning: Unhandled promise rejection. This error originated either by throwing inside of an async function without a catch block, or by rejecting a promise which was not handled with .catch(). (rejection id: 1)
(node:2612) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
</code></pre></div>
<p dir="auto">Could be related to jest-jasmine2...</p>
<p dir="auto"><a href="https://travis-ci.org/webpack/webpack/jobs/374782908" rel="nofollow">https://travis-ci.org/webpack/webpack/jobs/374782908</a><br>
<a href="https://travis-ci.org/webpack/webpack/jobs/374782909" rel="nofollow">https://travis-ci.org/webpack/webpack/jobs/374782909</a><br>
<a href="https://ci.appveyor.com/project/sokra/webpack/build/1.0.7531/job/7m1jbsafpkt4sh5o" rel="nofollow">https://ci.appveyor.com/project/sokra/webpack/build/1.0.7531/job/7m1jbsafpkt4sh5o</a></p>
<p dir="auto"><code class="notranslate">forceExit: true</code> didn't help</p>
<ul class="contains-task-list">
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> There is no shortcut for <code class="notranslate">--testPathPattern</code> i. e. <code class="notranslate">-p</code> similar to <code class="notranslate">-t</code></p>
</li>
<li class="task-list-item">
<p dir="auto"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> watch mode with single test suite and a lot of skipped test cases is very spammy</p>
</li>
</ul>
<p dir="auto">Example:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="yarn test:integration -t runtime-chunk --watch --testPathPattern ConfigTestCases"><pre class="notranslate"><code class="notranslate">yarn test:integration -t runtime-chunk --watch --testPathPattern ConfigTestCases
</code></pre></div>
<p dir="auto">Prints:</p>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content=" PASS  test\ConfigTestCases.test.js
  ConfigTestCases
    additional-pass
      simple
        ○ skipped 1 test
    async-commons-chunk
      all-selected
        ○ skipped 1 test
      duplicate
        ○ skipped 1 test
      existing-name
        ○ skipped 1 test
      nested
        ○ skipped 1 test
      node
        ○ skipped 1 test
      simple
        ○ skipped 1 test
    code-generation
      require-context-id
        ○ skipped 1 test
      use-strict
        ○ skipped 1 test
... (many many lines)
      runtime-chunk
        √ runtime-chunk should compile (754ms)
        exported tests
          √ should be able to load the split chunk on demand (6ms)
      runtime-chunk-no-async
        √ runtime-chunk-no-async should compile (105ms)
        exported tests
          √ should compile and evaluate fine
    target
      buffer
        ○ skipped 1 test
      buffer-default
        ○ skipped 1 test
... (some more lines)"><pre class="notranslate"><code class="notranslate"> PASS  test\ConfigTestCases.test.js
  ConfigTestCases
    additional-pass
      simple
        ○ skipped 1 test
    async-commons-chunk
      all-selected
        ○ skipped 1 test
      duplicate
        ○ skipped 1 test
      existing-name
        ○ skipped 1 test
      nested
        ○ skipped 1 test
      node
        ○ skipped 1 test
      simple
        ○ skipped 1 test
    code-generation
      require-context-id
        ○ skipped 1 test
      use-strict
        ○ skipped 1 test
... (many many lines)
      runtime-chunk
        √ runtime-chunk should compile (754ms)
        exported tests
          √ should be able to load the split chunk on demand (6ms)
      runtime-chunk-no-async
        √ runtime-chunk-no-async should compile (105ms)
        exported tests
          √ should compile and evaluate fine
    target
      buffer
        ○ skipped 1 test
      buffer-default
        ○ skipped 1 test
... (some more lines)
</code></pre></div>
<ul class="contains-task-list">
<li class="task-list-item"><input type="checkbox" id="" disabled="" class="task-list-item-checkbox"> This message appears:</li>
</ul>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="    &quot;transformIgnorePatterns&quot;: [
      &quot;&lt;rootDir&gt;/&quot;
    ]"><pre class="notranslate"><code class="notranslate">    "transformIgnorePatterns": [
      "&lt;rootDir&gt;/"
    ]
</code></pre></div>
<div class="snippet-clipboard-content notranslate position-relative overflow-auto" data-snippet-clipboard-copy-content="[BABEL] Note: The code generator has deoptimised the styling of &quot;/home/travis/build/webpack/webpack/node_modules/text-encoding/lib/encoding-indexes.js&quot; as it exceeds the max of &quot;500KB&quot;."><pre class="notranslate"><code class="notranslate">[BABEL] Note: The code generator has deoptimised the styling of "/home/travis/build/webpack/webpack/node_modules/text-encoding/lib/encoding-indexes.js" as it exceeds the max of "500KB".
</code></pre></div>