Skip to content

Commit 92c4650

Browse files
fix: report the missing module when a code generation dependency resolved to nothing (#21992)
* fix: generate code for a module whose codegen dependency has no module A dependency registered with `addCodeGenerationDependency` that resolved to nothing can never be code-generated, so the scheduler waited on it forever. When every remaining job waited that way it reported a circular code generation dependency instead, hiding the module-not-found error behind an internal one. An html page referencing a missing asset, and a stylesheet with a missing `url()`, both hit this in production once concatenation left a single job. Both now report what is actually missing and render the same `data:,` placeholder development already rendered. * test(test262): give the strict scenario's directive to the parser The scenario prepended "use strict" to the assembled bundle, so webpack read every strict-scenario file as sloppy code and accepted what only strict mode rejects. A loader now puts the directive in the source webpack parses, on line one so diagnostics keep pointing at the original lines. That un-skips the case pinning the gap: `import('...', yield)` is a SyntaxError only in strict mode, which webpack already reports once it reads the file strictly. * test(hmr): say why the shared module is disposed in this case The case name and comment read as an unfixed defect, but dropping [runtime] from output.hotUpdateMainFilename is exactly what the plugin warns about here: the colliding manifests merge, so one runtime applies the other's removals. Both now say that is what the case asserts. * test(hmr): let the extracted-stylesheet cases fail Both read a stylesheet under a name nothing emits, with every expectation inside an empty catch, so the read threw and the case passed having asserted nothing. They now read the file that is emitted and let the assertion through, which is what pins the red -> blue -> green sequence a hot update applies. The filters said the other runners run out of memory. They do not: the cases pin target "web" themselves, so another runner rebuilds the same bundle. * test(test262): insert the strict directive as INTERPRETING.md defines it The transformation is specified as the directive, a semicolon and a newline as the file's initial character sequence. Keeping it on line 1 preserved the source's line numbers but is not what the document says, and it only stayed safe because every hashbang case carries the raw flag.
1 parent ee66ae8 commit 92c4650

21 files changed

Lines changed: 164 additions & 59 deletions

File tree

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
---
2+
"webpack": patch
3+
---
4+
5+
Report a missing asset instead of a code generation deadlock.

‎lib/Compilation.js‎

Lines changed: 11 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -4223,15 +4223,17 @@ Or do you want to use the entrypoints '${name}' and '${runtime}' independently o
42234223
const { codeGenerationDependencies } = module;
42244224
if (
42254225
codeGenerationDependencies !== undefined &&
4226-
(notCodeGeneratedModules === undefined ||
4227-
codeGenerationDependencies.some((dep) => {
4228-
const referencedModule = /** @type {Module} */ (
4229-
moduleGraph.getModule(dep)
4230-
);
4231-
return /** @type {NotCodeGeneratedModules} */ (
4232-
notCodeGeneratedModules
4233-
).has(referencedModule);
4234-
}))
4226+
codeGenerationDependencies.some((dep) => {
4227+
const referencedModule = moduleGraph.getModule(dep);
4228+
// Nothing resolved it, so it is never code-generated and
4229+
// waiting on it would stall instead of ordering anything.
4230+
if (!referencedModule) return false;
4231+
return (
4232+
notCodeGeneratedModules === undefined ||
4233+
/** @type {NotCodeGeneratedModules} */
4234+
(notCodeGeneratedModules).has(referencedModule)
4235+
);
4236+
})
42354237
) {
42364238
delayedJobs.push(job);
42374239
delayedModules.add(module);
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`ConfigCacheTestCases css missing-url exported tests should report a module-not-found error rather than stall code generation 1`] = `
4+
"/*!***********************!*\\\\
5+
!*** css ./style.css ***!
6+
\\\\***********************/
7+
.a {
8+
background: url(data:,);
9+
}
10+
11+
"
12+
`;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`ConfigTestCases css missing-url exported tests should report a module-not-found error rather than stall code generation 1`] = `
4+
"/*!***********************!*\\\\
5+
!*** css ./style.css ***!
6+
\\\\***********************/
7+
.a {
8+
background: url(data:,);
9+
}
10+
11+
"
12+
`;
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
"use strict";
2+
3+
module.exports = [[/Can't resolve '\.\/missing\.png'/]];
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
import fs from "fs";
2+
import path from "path";
3+
import "./style.css";
4+
5+
it("should report a module-not-found error rather than stall code generation", () => {
6+
const name = fs.readdirSync(__dirname).find((f) => f.endsWith(".css"));
7+
expect(fs.readFileSync(path.join(__dirname, name), "utf-8")).toMatchSnapshot();
8+
});
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
.a {
2+
background: url("./missing.png");
3+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {
5+
mode: "production",
6+
target: "web",
7+
experiments: {
8+
css: true
9+
},
10+
optimization: {
11+
// Production drops the bundle on a build error, so the stylesheet this
12+
// case reads back would never be emitted.
13+
emitOnErrors: true
14+
},
15+
externalsPresets: {
16+
node: true
17+
},
18+
node: {
19+
__dirname: false
20+
}
21+
};
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`ConfigCacheTestCases html missing-asset exported tests should report a module-not-found error and render a data: placeholder 1`] = `
4+
"<!DOCTYPE html>
5+
<html>
6+
<head><title>missing-asset</title></head>
7+
<body>
8+
<img src=\\"data:,\\">
9+
</body>
10+
</html>
11+
"
12+
`;
Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,12 @@
1+
// Jest Snapshot v1, https://jestjs.io/docs/snapshot-testing
2+
3+
exports[`ConfigTestCases html missing-asset exported tests should report a module-not-found error and render a data: placeholder 1`] = `
4+
"<!DOCTYPE html>
5+
<html>
6+
<head><title>missing-asset</title></head>
7+
<body>
8+
<img src=\\"data:,\\">
9+
</body>
10+
</html>
11+
"
12+
`;

0 commit comments

Comments
 (0)