Skip to content

Commit e0a4a09

Browse files
fix: error message for missing default export in configuration (#3685)
1 parent f642f8d commit e0a4a09

File tree

3 files changed

+22
-0
lines changed

3 files changed

+22
-0
lines changed

packages/webpack-cli/src/webpack-cli.ts

+5
Original file line numberDiff line numberDiff line change
@@ -1772,6 +1772,11 @@ class WebpackCLI implements IWebpackCLI {
17721772
process.exit(2);
17731773
}
17741774

1775+
if (!options) {
1776+
this.logger.error(`Failed to load '${configPath}' config. Unable to find default export.`);
1777+
process.exit(2);
1778+
}
1779+
17751780
if (Array.isArray(options)) {
17761781
// reassign the value to assert type
17771782
const optionsArray: ConfigOptions[] = options;
+16
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const { run } = require("../../../utils/test-utils");
2+
3+
describe("webpack cli", () => {
4+
it("should support mjs config format", async () => {
5+
const { exitCode, stderr } = await run(__dirname, ["-c", "webpack.config.mjs"], {
6+
env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true },
7+
});
8+
9+
if (/Error: Not supported/.test(stderr)) {
10+
expect(exitCode).toBe(2);
11+
} else {
12+
expect(exitCode).toBe(2);
13+
expect(stderr).toMatch(/Unable to find default export./);
14+
}
15+
});
16+
});
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
export let config = {};

0 commit comments

Comments
 (0)