Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Appearance settings

Commit 5106684

Browse filesBrowse files
fix: allow require webpack.config.js in ESM format (#4346)
1 parent 3642966 commit 5106684
Copy full SHA for 5106684

File tree

Expand file treeCollapse file tree

11 files changed

+52
-20
lines changed
Open diff view settings
Filter options
Expand file treeCollapse file tree

11 files changed

+52
-20
lines changed
Open diff view settings
Collapse file

‎.eslintignore‎

Copy file name to clipboardExpand all lines: .eslintignore
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,4 +10,5 @@ test/**/index.js
1010
test/build/config/error-commonjs/syntax-error.js
1111
test/build/config/error-mjs/syntax-error.mjs
1212
test/build/config/error-array/webpack.config.js
13+
test/build/config-format/esm-require-await/webpack.config.js
1314
test/configtest/with-config-path/syntax-error.config.js
Collapse file

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

Copy file name to clipboardExpand all lines: packages/webpack-cli/src/webpack-cli.ts
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -351,6 +351,7 @@ class WebpackCLI implements IWebpackCLI {
351351
require("./utils/dynamic-import-loader")();
352352
if (
353353
((error as ImportLoaderError).code === "ERR_REQUIRE_ESM" ||
354+
(error as ImportLoaderError).code === "ERR_REQUIRE_ASYNC_MODULE" ||
354355
process.env.WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG) &&
355356
pathToFileURL &&
356357
dynamicImportLoader
Collapse file

‎test/build/config-format/babel-commonjs/babel-esm.test.js‎

Copy file name to clipboardExpand all lines: test/build/config-format/babel-commonjs/babel-esm.test.js
-2Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@ describe("webpack cli", () => {
55
it("should support mjs config format", async () => {
66
const { exitCode, stderr, stdout } = await run(__dirname, ["-c", "webpack.config.babel.js"]);
77

8-
console.log(stderr);
9-
108
expect(exitCode).toBe(0);
119
expect(stderr).toBeFalsy();
1210
expect(stdout).toBeTruthy();
Collapse file

‎test/build/config-format/babel-esm/babel-esm.test.js‎

Copy file name to clipboardExpand all lines: test/build/config-format/babel-esm/babel-esm.test.js
-12Lines changed: 0 additions & 12 deletions
This file was deleted.
Collapse file

‎test/build/config-format/babel-esm/package.json‎

Copy file name to clipboardExpand all lines: test/build/config-format/babel-esm/package.json
-6Lines changed: 0 additions & 6 deletions
This file was deleted.
Collapse file
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { run } = require("../../../utils/test-utils");
2+
3+
describe("webpack cli", () => {
4+
it("should support mjs config format using `require`", async () => {
5+
const { exitCode, stdout } = await run(__dirname, ["-c", "webpack.config.js"]);
6+
7+
const [major, minor] = process.versions.node.split(".").map(Number);
8+
9+
if ((major >= 22 && minor >= 11) || major >= 23) {
10+
expect(exitCode).toBe(0);
11+
// stderr contains - Support for loading ES Module in require() is an experimental feature and might change at any time
12+
// expect(stderr).toBeFalsy();
13+
expect(stdout).toBeTruthy();
14+
} else {
15+
expect(exitCode).toBe(2);
16+
}
17+
});
18+
});
Collapse file
File renamed without changes.
Collapse file
+13Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
import { fileURLToPath } from "url";
2+
import path from "path";
3+
4+
const mode = await "development";
5+
6+
export default {
7+
mode,
8+
entry: "./main.js",
9+
output: {
10+
path: path.resolve(path.dirname(fileURLToPath(import.meta.url)), "dist"),
11+
filename: "foo.bundle.js",
12+
},
13+
};
Collapse file
+18Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
const { run } = require("../../../utils/test-utils");
2+
3+
describe("webpack cli", () => {
4+
it("should support mjs config format using `require`", async () => {
5+
const { exitCode, stdout } = await run(__dirname, ["-c", "webpack.config.js"]);
6+
7+
const [major, minor] = process.versions.node.split(".").map(Number);
8+
9+
if ((major >= 22 && minor >= 11) || major >= 23) {
10+
expect(exitCode).toBe(0);
11+
// stderr contains - Support for loading ES Module in require() is an experimental feature and might change at any time
12+
// expect(stderr).toBeFalsy();
13+
expect(stdout).toBeTruthy();
14+
} else {
15+
expect(exitCode).toBe(2);
16+
}
17+
});
18+
});
Collapse file
+1Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
console.log("You know who");

0 commit comments

Comments
0 (0)
Morty Proxy This is a proxified and sanitized view of the page, visit original site.