Skip to content

Having multiple entries break module concatenation #10720

Closed

Description

@fregante

Minimal repro repo: https://github.com/fregante/webpack-concat-fail-demo

Bug report

Module concatenation bails out simply when there are 2 entries in the config. This is the minimal repro. The diff shows the breaking point

  {
  	devtool: 'source-map',
  	entry: {
  		a: './a',
+  		b: './b',
  	},
  	optimization: {
  		concatenateModules: true,
  	}
  };
// This is the common imported module
export const isTrue = () => true;
// Both a.js and b.js have this
import {isTrue} from './module';

isTrue()

What is the current behavior?

The common import "module.js" is no longer concatenated when you have 2 entry points. Even the dist/a.js output changes simply after adding b: './b':

@@ -87,23 +87,34 @@
 /******/ ({
 
 /***/ "./a.js":
-/*!**************************!*\
-  !*** ./a.js + 1 modules ***!
-  \**************************/
+/*!**************!*\
+  !*** ./a.js ***!
+  \**************/
 /*! no exports provided */
+/*! ModuleConcatenation bailout: Module is an entry point */
 /***/ (function(module, __webpack_exports__, __webpack_require__) {
 
 "use strict";
-// ESM COMPAT FLAG
 __webpack_require__.r(__webpack_exports__);
+/* harmony import */ var _module__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(/*! ./module */ "./module.js");
 
-// CONCATENATED MODULE: ./module.js
-const isTrue = () => true;
 
-// CONCATENATED MODULE: ./a.js
+Object(_module__WEBPACK_IMPORTED_MODULE_0__["isTrue"])()
+
 
+/***/ }),
+
+/***/ "./module.js":
+/*!*******************!*\
+  !*** ./module.js ***!
+  \*******************/
+/*! exports provided: isTrue */
+/***/ (function(module, __webpack_exports__, __webpack_require__) {
 
-isTrue()
+"use strict";
+__webpack_require__.r(__webpack_exports__);
+/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "isTrue", function() { return isTrue; });
+const isTrue = () => true;
 
 
 /***/ })

You can see the full diff output here: https://github.com/fregante/webpack-concat-fail-demo/commit/d3570f8648b339ca8f19c2770c6dcd0d9d9a2318

What is the expected behavior?
Having multiple entries should not affect the output of the first entry.

This is the regular output with just one entry point:

// CONCATENATED MODULE: ./module.js
const isTrue = () => true;

// CONCATENATED MODULE: ./a.js
isTrue();

If the current behavior is a bug, please provide the steps to reproduce.

https://github.com/fregante/webpack-concat-fail-demo

Other relevant information:
webpack version: 4.42.1
Node.js version: v12.15.0
Operating System: macOS 10.15.3
Additional tools:

Activity

  1. fregante commented on Apr 16, 2020

    @fregante
    ContributorAuthor

    Webpack v5.0.0-beta.13 is affected by the same bug

  2. sokra commented on Apr 16, 2020

    @sokra
    Member

    Just because it's not concatenated it's not broken. The bundle should still behave the same.

    You are requesting to improve that, it's not really a bug.

  3. fregante commented on Apr 16, 2020

    @fregante
    ContributorAuthor

    The bundle isn't broken indeed, but the specific feature is (i.e. it isn't working as it should), therefore it is a bug... just not a "breaking bug" 😅

  4. webpack-bot commented on Jul 20, 2020

    @webpack-bot
    Contributor

    This issue had no activity for at least three months.

    It's subject to automatic issue closing if there is no activity in the next 15 days.

  5. added
    status: stale
    and removed
    status: stale
    on Jul 20, 2020
  6. added
    status: stale
    and removed
    status: stale
    on Oct 19, 2020
  7. fregante commented on Oct 24, 2020

    @fregante
    ContributorAuthor

    This appears to be fixed in 5.2.0 🎉

  8. fregante commented on Oct 24, 2020

    @fregante
    ContributorAuthor

    Here are the 2 outputted files in full:

    /******/ (() => { // webpackBootstrap
    /******/ 	"use strict";
    /******/ 	var __webpack_modules__ = ({
    
    /***/ "./a.js":
    /*!**************************!*\
      !*** ./a.js + 1 modules ***!
      \**************************/
    /*! namespace exports */
    /*! exports [not provided] [no usage info] */
    /*! runtime requirements: __webpack_require__.r, __webpack_exports__, __webpack_require__.* */
    /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
    
    // ESM COMPAT FLAG
    __webpack_require__.r(__webpack_exports__);
    
    // CONCATENATED MODULE: ./module.js
    const isTrue = () => true;
    
    // CONCATENATED MODULE: ./a.js
    
    
    isTrue()
    
    
    /***/ })
    
    /******/ 	});
    /************************************************************************/
    /******/ 	// The module cache
    /******/ 	var __webpack_module_cache__ = {};
    /******/ 	
    /******/ 	// The require function
    /******/ 	function __webpack_require__(moduleId) {
    /******/ 		// Check if module is in cache
    /******/ 		if(__webpack_module_cache__[moduleId]) {
    /******/ 			return __webpack_module_cache__[moduleId].exports;
    /******/ 		}
    /******/ 		// Create a new module (and put it into the cache)
    /******/ 		var module = __webpack_module_cache__[moduleId] = {
    /******/ 			// no module.id needed
    /******/ 			// no module.loaded needed
    /******/ 			exports: {}
    /******/ 		};
    /******/ 	
    /******/ 		// Execute the module function
    /******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
    /******/ 	
    /******/ 		// Return the exports of the module
    /******/ 		return module.exports;
    /******/ 	}
    /******/ 	
    /************************************************************************/
    /******/ 	/* webpack/runtime/make namespace object */
    /******/ 	(() => {
    /******/ 		// define __esModule on exports
    /******/ 		__webpack_require__.r = (exports) => {
    /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    /******/ 			}
    /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
    /******/ 		};
    /******/ 	})();
    /******/ 	
    /************************************************************************/
    /******/ 	// startup
    /******/ 	// Load entry module
    /******/ 	__webpack_require__("./a.js");
    /******/ 	// This entry module used 'exports' so it can't be inlined
    /******/ })()
    ;
    /******/ (() => { // webpackBootstrap
    /******/ 	"use strict";
    /******/ 	var __webpack_modules__ = ({
    
    /***/ "./b.js":
    /*!**************************!*\
      !*** ./b.js + 1 modules ***!
      \**************************/
    /*! namespace exports */
    /*! exports [not provided] [no usage info] */
    /*! runtime requirements: __webpack_require__.r, __webpack_exports__, __webpack_require__.* */
    /***/ ((__unused_webpack_module, __webpack_exports__, __webpack_require__) => {
    
    // ESM COMPAT FLAG
    __webpack_require__.r(__webpack_exports__);
    
    // CONCATENATED MODULE: ./module.js
    const isTrue = () => true;
    
    // CONCATENATED MODULE: ./b.js
    
    
    isTrue()
    
    
    /***/ })
    
    /******/ 	});
    /************************************************************************/
    /******/ 	// The module cache
    /******/ 	var __webpack_module_cache__ = {};
    /******/ 	
    /******/ 	// The require function
    /******/ 	function __webpack_require__(moduleId) {
    /******/ 		// Check if module is in cache
    /******/ 		if(__webpack_module_cache__[moduleId]) {
    /******/ 			return __webpack_module_cache__[moduleId].exports;
    /******/ 		}
    /******/ 		// Create a new module (and put it into the cache)
    /******/ 		var module = __webpack_module_cache__[moduleId] = {
    /******/ 			// no module.id needed
    /******/ 			// no module.loaded needed
    /******/ 			exports: {}
    /******/ 		};
    /******/ 	
    /******/ 		// Execute the module function
    /******/ 		__webpack_modules__[moduleId](module, module.exports, __webpack_require__);
    /******/ 	
    /******/ 		// Return the exports of the module
    /******/ 		return module.exports;
    /******/ 	}
    /******/ 	
    /************************************************************************/
    /******/ 	/* webpack/runtime/make namespace object */
    /******/ 	(() => {
    /******/ 		// define __esModule on exports
    /******/ 		__webpack_require__.r = (exports) => {
    /******/ 			if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
    /******/ 				Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
    /******/ 			}
    /******/ 			Object.defineProperty(exports, '__esModule', { value: true });
    /******/ 		};
    /******/ 	})();
    /******/ 	
    /************************************************************************/
    /******/ 	// startup
    /******/ 	// Load entry module
    /******/ 	__webpack_require__("./b.js");
    /******/ 	// This entry module used 'exports' so it can't be inlined
    /******/ })()
    ;
  9. alexander-akait commented on Oct 24, 2020

    @alexander-akait
    Member

    Terser remove all junks for production mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    Priority

    None yet

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions