-
-
Notifications
You must be signed in to change notification settings - Fork 9.4k
Description
Bug report
What is the current behavior?
When concatenateModules is enabled in Webpack’s production build, some modules are inlined directly into the bundle. This causes variable names from the included module to conflict with Webpack’s internal variable names, specifically the i variable in this case. The resulting bundle outputs an error:
var __webpack_export_target__ = exports;
for(var i in __webpack_exports__) __webpack_export_target__[i] = __webpack_exports__[i];
if(__webpack_exports__.__esModule) Object.defineProperty(__webpack_export_target__, "__esModule", { value: true });
/******/ })();Error in bundled file:
Cannot redeclare block-scoped variable 'i'.ts(2451)
(local var) i: stringThis error arises from the i variable declared in an imported module (ruleset.js in this case), which conflicts with Webpack’s internal loop variable.
If the current behavior is a bug, please provide the steps to reproduce.
- Enable concatenateModules in Webpack’s production build configuration.
- Include a module (e.g., ruleset.js from @aws-sdk/client-lambda) that declares a variable (i in this case) with the same name as an internal variable in Webpack’s output.
- Build the project with Webpack, then inspect the bundled file and observe the variable name collision.
Relevant code from ruleset.js:
;// ./node_modules/@aws-sdk/client-lambda/dist-es/endpoint/ruleset.js
const s = "required", t = "fn", u = "argv", v = "ref";
const a = true, b = "isSet", c = "booleanEquals", d = "error", e = "endpoint", f = "tree", g = "PartitionResult", h = { [s]: false, "type": "String" }, i = { [s]: true, "default": false, "type": "Boolean" }, ...What is the expected behavior?
Webpack should ensure that internal variables do not collide with variables in bundled modules. A recommended fix would be to prefix internal variables with a unique identifier, such as __webpack_i__, to prevent such conflicts.
Other relevant information:
- webpack version: v5.96.1
- Node.js version: v22.11.0
- Operating System: MacOS
- Additional tools: N/A