GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||
GeezerVison is showing github.com — [5.107.1 regression] CommonJS tree-shaking drops exports used through a `const X = require(...)` binding declared at the bottom of the file · Issue #21122 · webpack/webpack Closed DescriptionBug reportWhat is the current behavior? Since webpack 5.107.1, CommonJS tree-shaking (introduced in #21003, "tree-shake CommonJS exports through This is the exact code shape that webidl2js generates for every wrapper class in whatwg-url (the require is placed at the end of the file to handle circular dependencies): // whatwg-url/lib/URL.js (generated by webidl2js) exports.setup = (wrapper, globalObject, constructorArgs, privateData) => { // ... new Impl.implementation(constructorArgs, globalObject, privateData) // ... } // ~700 lines later, last line of the file: const Impl = require("./URL-impl.js"); // whatwg-url/lib/URL-impl.js exports.implementation = class URLImpl { /* ... */ }; With webpack >= 5.107.1 (production mode, Real-world impact: any server bundle containing Minimal reproductionThree files, no dependencies: // src/impl.js exports.implementation = class URLImpl { constructor(args) { this.href = args[0] } } // src/wrapper.js exports.setup = (obj, constructorArgs) => { obj._impl = new Impl.implementation(constructorArgs) // ref BEFORE the declaration below return obj } class URL { constructor(url) { return exports.setup(Object.create(new.target.prototype), [url]) } } exports.interface = URL // deferred require (handles circular dependencies), as generated by webidl2js const Impl = require("./impl.js") // src/entry.js const { interface: URL } = require("./wrapper.js") const u = new URL("https://example.com/") console.log("OK", u._impl.href) // webpack.config.js module.exports = { entry: './src/entry.js', mode: 'production', optimization: { minimize: false }, // minimization not required to reproduce output: { filename: 'bundle.js' }, target: 'node', } $ npx webpack && node dist/bundle.js TypeError: Impl.implementation is not a constructor at exports.setup (dist/bundle.js:21:15) at new URL (dist/bundle.js:27:20) The emitted bundle contains no assignment to Moving Alternatively, reproducible with the real packages: // entry.js const ConnectionString = require('mongodb-connection-string-url').default new ConnectionString('mongodb://localhost/test') // throws with webpack >= 5.107.1 Bisection
Introduced by #21003. What is the expected behavior? Property reads on the required-module binding should count as export usages regardless of where they appear lexically relative to the Environment
Reacted by Trystan SARRADE ActivityMetadataMetadataAssigneesLabelsNo labels TypeFieldsPriority None yet ProjectsMilestoneRelationshipsDevelopmentIssue actions | ||||||||||
| You are visitor 01402775 — GeezerVison does not store the pages you look up. Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required. |