Minimal reproduction for a code generation bug in webpack 5.110.3. The same input builds and runs correctly on 5.110.2.
npm install
npm run build
npm startExpected: loaded object
Actual (5.110.3):
TypeError: Cannot set properties of undefined (setting 'options')
at e.exports (out/bundle.js:2:185867)
at Object.<anonymous> (out/bundle.js:2:152584)
To confirm it is a regression:
npm i -D [email protected] && npm run build && npm start # prints "loaded object"
npm i -D [email protected] && npm run build && npm start # throws[email protected] is written without semicolons, and index.js re-exports like this:
module.exports.Type = require('./lib/type')
module.exports.Schema = require('./lib/schema')
module.exports.FAILSAFE_SCHEMA = require('./lib/schema/failsafe')
module.exports.JSON_SCHEMA = require('./lib/schema/json')
module.exports.CORE_SCHEMA = require('./lib/schema/core')
module.exports.DEFAULT_SCHEMA = require('./lib/schema/default')
module.exports.load = loader.loadelectron-updater only reads load, so the six re-exports above are unused and their
assignments are dropped. On 5.110.3 the remaining references are emitted wrapped in
parentheses and without a separating semicolon, so consecutive statements merge:
Ge()(Fe())(Be())(Ve())(je())(Ue()),e.exports.load=r.load, …Ge() returns js-yaml's Type constructor, which is now called as a plain function.
The module is in strict mode, so this is undefined and this.options = options
throws while the bundle is still loading.
Search out/bundle.js for is removed in js-yaml 4 to see the emitted code.
- An ES module entry is required — concatenation starts at the ESM root and pulls the CommonJS dependencies in. With a CommonJS entry the output is fine.
[email protected]is unaffected: it is written with semicolons, so dropping the assignments still leaves separate statements.- Workarounds:
optimization.concatenateModules: { commonjs: false }oroptimization.usedExports: false. electron-stub.jsonly exists so the bundle can run under plain Node; Electron itself is not needed to reproduce the bad output.