Skip to content

Commit 5a97898

Browse files
fix: declare the require scope for the CSS server styles helper
The helper assigns onto `__webpack_require__.cs`, but nothing pulled in the require scope, so a bundle whose only runtime consumer was `__webpack_css_server_styles__` threw before reaching the entry. The `globalThis` polyfill hid this whenever the target lacked `globalThis`.
1 parent 4a759f0 commit 5a97898

4 files changed

Lines changed: 29 additions & 0 deletions

File tree

‎lib/RuntimePlugin.js‎

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -67,6 +67,7 @@ const GLOBALS_ON_REQUIRE = [
6767
RuntimeGlobals.definePropertyGetters,
6868
RuntimeGlobals.ensureChunk,
6969
RuntimeGlobals.entryModuleId,
70+
RuntimeGlobals.getCssServerStyles,
7071
RuntimeGlobals.getFullHash,
7172
RuntimeGlobals.global,
7273
RuntimeGlobals.makeNamespaceObject,
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
// no CSS import: the module variable is the only thing pulling in runtime
2+
it("works when the collected styles are the only runtime consumer", () => {
3+
expect(__webpack_css_server_styles__).toBe("");
4+
});
Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
"use strict";
2+
3+
const supportsGlobalThis = require("../../../helpers/supportsGlobalThis");
4+
5+
module.exports = () => supportsGlobalThis();
Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {
5+
devtool: false,
6+
target: ["web", "node"],
7+
mode: "development",
8+
experiments: {
9+
css: true
10+
},
11+
output: {
12+
uniqueName: "alone",
13+
// without `globalThis` the registry pulls in the global polyfill, which
14+
// would bring the require scope along and hide a missing one here
15+
environment: {
16+
globalThis: true
17+
}
18+
}
19+
};

0 commit comments

Comments
 (0)