Skip to content

Commit

Permalink
fix: error message for missing default export in configuration (#3685)
Browse files Browse the repository at this point in the history
  • Loading branch information
alexander-akait committed Mar 19, 2023
1 parent f642f8d commit e0a4a09
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 0 deletions.
5 changes: 5 additions & 0 deletions packages/webpack-cli/src/webpack-cli.ts
Original file line number Diff line number Diff line change
Expand Up @@ -1772,6 +1772,11 @@ class WebpackCLI implements IWebpackCLI {
process.exit(2);
}

if (!options) {
this.logger.error(`Failed to load '${configPath}' config. Unable to find default export.`);
process.exit(2);
}

if (Array.isArray(options)) {
// reassign the value to assert type
const optionsArray: ConfigOptions[] = options;
Expand Down
16 changes: 16 additions & 0 deletions test/build/config/named-export/mjs.test.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
const { run } = require("../../../utils/test-utils");

describe("webpack cli", () => {
it("should support mjs config format", async () => {
const { exitCode, stderr } = await run(__dirname, ["-c", "webpack.config.mjs"], {
env: { WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG: true },
});

if (/Error: Not supported/.test(stderr)) {
expect(exitCode).toBe(2);
} else {
expect(exitCode).toBe(2);
expect(stderr).toMatch(/Unable to find default export./);
}
});
});
1 change: 1 addition & 0 deletions test/build/config/named-export/webpack.config.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
export let config = {};

0 comments on commit e0a4a09

Please sign in to comment.