Skip to content

Commit d16b388

Browse files
fix: report import.meta errors raised inside async require callbacks
1 parent 6cabcf3 commit d16b388

6 files changed

Lines changed: 27 additions & 2 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 `import.meta` option errors inside `require.ensure` callbacks, not crash.

‎lib/dependencies/context/ImportMetaContextDependencyParserPlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -301,7 +301,7 @@ module.exports = class ImportMetaContextDependencyParserPlugin {
301301
}
302302
}
303303
if (errors.length) {
304-
for (const error of errors) parser.state.current.addError(error);
304+
for (const error of errors) parser.state.module.addError(error);
305305
return;
306306
}
307307

‎lib/dependencies/context/ImportMetaGlobDependencyParserPlugin.js‎

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -43,7 +43,7 @@ module.exports = class ImportMetaGlobDependencyParserPlugin {
4343
parser.state.module.addWarning(warning);
4444
}
4545
if (errors.length) {
46-
for (const error of errors) parser.state.current.addError(error);
46+
for (const error of errors) parser.state.module.addError(error);
4747
return;
4848
}
4949
if (!globOptions) return;
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
"use strict";
2+
3+
module.exports = [
4+
[{ message: /Unknown property "unknownOption"/ }],
5+
[{ message: /import\.meta\.glob\(\) requires 1 or 2 arguments/ }]
6+
];
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
it("should report import.meta errors raised inside an async block", () => {
2+
if (typeof __nonexistent__ !== "undefined") {
3+
require.ensure([], () => {
4+
import.meta.webpackContext("./dir", { unknownOption: 1 });
5+
});
6+
require(["./index.js"], () => {
7+
import.meta.glob();
8+
});
9+
}
10+
});
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
"use strict";
2+
3+
/** @type {import("../../../../").Configuration} */
4+
module.exports = {};

0 commit comments

Comments
 (0)