<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong></p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong></p>






<p dir="auto"><strong>What is the expected behavior?</strong></p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:<br>
Node.js version:<br>
Operating System:<br>
Additional tools:</p>
<p dir="auto">{<br>
"name": "mf-demo",<br>
"version": "0.0.0",<br>
"scripts": {<br>
"ng": "ng",<br>
"start": "npm run start:shell",<br>
"start:shell": "ng serve shell -o --port 5000",<br>
"start:mfe1": "ng serve mfe1 -o --port 3000",<br>
"start:all": "concurrently "npm run start:shell" "npm run start:mfe1" ",<br>
"build:shell": "ng build shell --prod",<br>
"build:mfe1": "ng build mfe1 --prod",<br>
"serve:dist": "concurrently "serve dist/shell -l 5000 -s" "serve dist/mfe1 -l 3000 -s" ",<br>
"build": "npm run build:shell &amp;&amp; npm run build:mfe1",<br>
"test": "ng test",<br>
"lint": "ng lint",<br>
"e2e": "ng e2e"<br>
},<br>
"private": true,<br>
"resolutions": {<br>
"webpack": "^5.0.0"<br>
},<br>
"dependencies": {<br>
"@angular-architects/module-federation": "^1.2.3",<br>
"@angular/animations": "11.2.4",<br>
"@angular/common": "11.2.4",<br>
"@angular/compiler": "^11.2.4",<br>
"@angular/core": "^11.2.4",<br>
"@angular/forms": "11.2.4",<br>
"@angular/platform-browser": "11.2.4",<br>
"@angular/platform-browser-dynamic": "11.2.4",<br>
"@angular/router": "11.2.4",<br>
"@nrwl/workspace": "^11.4.0",<br>
"concurrently": "^6.0.0",<br>
"rxjs": "^6.6.6",<br>
"tslib": "^2.1.0",<br>
"zone.js": "~0.11.4"<br>
},<br>
"devDependencies": {<br>
"@angular-devkit/build-angular": "^0.1102.3",<br>
"@angular/cli": "11.2.3",<br>
"@angular/compiler-cli": "^11.2.4",<br>
"@types/jasmine": "~3.6.6",<br>
"@types/jasminewd2": "~2.0.8",<br>
"@types/node": "^14.14.33",<br>
"codelyzer": "^6.0.1",<br>
"jasmine-core": "~3.6.0",<br>
"jasmine-spec-reporter": "~6.0.0",<br>
"karma": "~6.1.2",<br>
"karma-chrome-launcher": "~3.1.0",<br>
"karma-coverage": "~2.0.3",<br>
"karma-jasmine": "~4.0.1",<br>
"karma-jasmine-html-reporter": "^1.5.4",<br>
"ngx-build-plus": "^11.0.0",<br>
"protractor": "~7.0.0",<br>
"serve": "^11.3.2",<br>
"ts-node": "~9.1.1",<br>
"tslint": "~6.1.0",<br>
"typescript": "^4.1.5"<br>
}<br>
}</p>
<p dir="auto">An unhandled exception occurred: Invalid configuration object. Webpack has been initialised using a configuration object that does not match the API schema.</p>
<p dir="auto">configuration.output has an unknown property 'uniqueName'. These properties are valid:<br>
object { auxiliaryComment?, chunkCallbackName?, chunkFilename?, chunkLoadTimeout?, crossOriginLoading?, devtoolFallbackModuleFilenameTemplate?, devtoolLineToLine?, devtoolModuleFilenameTemplate?, devtoolNamespace?, filename?, futureEmitAssets?, globalObject?, hashDigest?, hashDigestLength?, hashFunction?, hashSalt?, hotUpdateChunkFilename?, hotUpdateFunction?, hotUpdateMainFilename?, jsonpFunction?, jsonpScriptType?, library?, libraryExport?, libraryTarget?, path?, pathinfo?, publicPath?, sourceMapFilename?, sourcePrefix?, strictModuleExceptionHandling?, umdNamedDefine?, webassemblyModuleFilename? }<br>
-&gt; Options affecting the output of the compilation. output options tell webpack how to write the compiled files to disk.<br>
See "C:\Users\Hugo Barboza\AppData\Local\Temp\ng-F3Qn1m\angular-errors.log" for further details.</p>
<h1 dir="auto">Bug report</h1>




<p dir="auto"><strong>What is the current behavior?</strong><br>
Under certain circumstances, modules in entrypoint chunks will be bundled into other async chunks.</p>
<p dir="auto"><strong>If the current behavior is a bug, please provide the steps to reproduce.</strong><br>
Here is the reproducible test repo: <a href="https://github.com/Mensu/webpack-reproduce-issue-15173">https://github.com/Mensu/webpack-reproduce-issue-15173</a></p>
<p dir="auto">To reproduce the issue, simply run <code class="notranslate">npm install</code> and <code class="notranslate">npm run build</code>. After the build is finished, search for <code class="notranslate">"moduleAB"</code> in the <code class="notranslate">dist</code> folder, and find out module <code class="notranslate">src/moduleAB.js</code> was bundled into chunk <code class="notranslate">dist/entryA.js</code>, chunk <code class="notranslate">dist/entryB.js</code> (entrypoint chunks, which is expected) and chunk <code class="notranslate">dist/commonAsync.js</code> (async chunks, which is unexpected)</p>
<p dir="auto">Module <code class="notranslate">src/moduleAB.js</code> is statically imported by entrypoint modules <code class="notranslate">src/entryA.js</code> and <code class="notranslate">src/entryB.js</code>, therefore is available in entrypoint chunks <code class="notranslate">dist/entryA.js</code> and <code class="notranslate">dist/entryB.js</code>. Since <code class="notranslate">dist/commonAsync.js</code> is an async chunk, the factory of module <code class="notranslate">src/moduleAB.js</code> must have been available in the entrypoint chunks when we are to load <code class="notranslate">dist/commonAsync.js</code>, therefore it seems unnecessary to duplicately bundle <code class="notranslate">src/moduleAB.js</code> into <code class="notranslate">dist/commonAsync.js</code>.</p>






<p dir="auto"><strong>What is the expected behavior?</strong><br>
Module <code class="notranslate">src/moduleAB.js</code> was only bundled into entrypoint chunks <code class="notranslate">dist/entryA.js</code> and <code class="notranslate">dist/entryB.js</code>, not into <code class="notranslate">dist/commonAsync.js</code>.</p>
<p dir="auto">I kind of believe the problem lies here <code class="notranslate">availableModules.has(module) || availableModules.plus.has(m)</code><br>
<a href="https://github.com/webpack/webpack/blob/v5.66.0/lib/buildChunkGraph.js#L906-L909">https://github.com/webpack/webpack/blob/v5.66.0/lib/buildChunkGraph.js#L906-L909</a></p>
<p dir="auto">The first condition checks whether <code class="notranslate">availableModules</code> has <code class="notranslate">module</code>, but when it comes to the second condition, it checks whether <code class="notranslate">availableModules.plus</code> has <code class="notranslate">m</code> instead of <code class="notranslate">module</code>, which is inconsistent with the first condition. I'm not sure whether checking against <code class="notranslate">m</code> is intended for some reason I'm missing, or it's just a typo. Changing the condition to <code class="notranslate">availableModules.plus.has(module)</code> may fix this issue, but I don't know whether the change will break other codes or not.</p>


<p dir="auto"><strong>Other relevant information:</strong><br>
webpack version:  5.66.0<br>
Node.js version: 12.10.0<br>
Operating System: Mac OS<br>
Additional tools: N/A</p>