Skip to content

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Latest commit

 

History

1 Commit

Folders and files

Repository files navigation

webpack: unused CommonJS re-exports are concatenated into a call chain

Minimal reproduction for a code generation bug in webpack 5.110.3. The same input builds and runs correctly on 5.110.2.

Run it

npm install
npm run build
npm start

Expected: 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

What goes wrong

[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.load

electron-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.

Notes

  • 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 } or optimization.usedExports: false.
  • electron-stub.js only exists so the bundle can run under plain Node; Electron itself is not needed to reproduce the bad output.

About

No description, website, or topics provided.

Resources

Stars

0 stars

Watchers

0 watching

Forks

Releases

Packages

Contributors

Languages