Skip to content

Emitting __webpack_require__ is sometimes not needed #20820

@dilyanpalauzov

Description

@dilyanpalauzov

Have you used AI?

No

Bug Description

With the test case from #20146 (comment) the output produces the following output.

In this case the lines starting with /******/ ⇔ the __webpack_require__ stuff is not needed, so it should not be part of the output.

/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/ 
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/        // define getter functions for harmony exports
/******/        __webpack_require__.d = (exports, definition) => {
/******/                for(var key in definition) {
/******/                        if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/                                Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/                        }
/******/                }
/******/        };
/******/ })();
/******/ 
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/        __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/ 


;// ./src/u.js
class A {
    constructor() {
        console.log("UU");
    }
};

/* harmony default export */ const u = (A);

;// ./src/index.js


/* harmony default export */ const src = (u);

export { src as default };

Link to Minimal Reproduction and step to reproduce

git clone https://github.com/dilyanpalauzov/webpack-i20146
cd webpack-i20146/
npm update && npm run bundle

Expected Behavior

Output does not include

/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/ 
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/        // define getter functions for harmony exports
/******/        __webpack_require__.d = (exports, definition) => {
/******/                for(var key in definition) {
/******/                        if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/                                Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/                        }
/******/                }
/******/        };
/******/ })();
/******/ 
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/        __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/ 

Actual Behavior

Output includes

/******/ // The require scope
/******/ var __webpack_require__ = {};
/******/ 
/************************************************************************/
/******/ /* webpack/runtime/define property getters */
/******/ (() => {
/******/        // define getter functions for harmony exports
/******/        __webpack_require__.d = (exports, definition) => {
/******/                for(var key in definition) {
/******/                        if(__webpack_require__.o(definition, key) && !__webpack_require__.o(exports, key)) {
/******/                                Object.defineProperty(exports, key, { enumerable: true, get: definition[key] });
/******/                        }
/******/                }
/******/        };
/******/ })();
/******/ 
/******/ /* webpack/runtime/hasOwnProperty shorthand */
/******/ (() => {
/******/        __webpack_require__.o = (obj, prop) => (Object.prototype.hasOwnProperty.call(obj, prop))
/******/ })();
/******/ 

Environment

System:
    OS: Linux 6.19 (Details not so relevant)
    CPU: (4) x64 (Details not so relevant)
    Memory: 980.96 MB / enough (Details not so relevant)
  Binaries:
    Node: 22.22.0 - /usr/bin/node
    Yarn: 4.6.0 - /usr/local/bin/yarn
    npm: 10.9.4 - /usr/bin/npm
  Browsers:
    (Not relevant)
  Packages:
    webpack: ^5.103.0 => 5.106.1 
    webpack-cli: ^6.0.1 => 6.0.1

Is this a regression?

None

Last Working Version

No response

Additional Context

No response

Metadata

Metadata

Assignees

No one assigned
    No fields configured for Feature.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions