Skip to content

Commit 6a9aac9

Browse files
authored
fix: compatibility with dynamic import (#3006)
1 parent 5a51043 commit 6a9aac9

File tree

5 files changed

+3
-27
lines changed

5 files changed

+3
-27
lines changed

packages/webpack-cli/bin/cli.js

+1-7
Original file line numberDiff line numberDiff line change
@@ -2,12 +2,6 @@
22

33
"use strict";
44

5-
const Module = require("module");
6-
7-
const originalModuleCompile = Module.prototype._compile;
8-
9-
require("v8-compile-cache");
10-
115
const importLocal = require("import-local");
126
const runCLI = require("../lib/bootstrap");
137

@@ -20,4 +14,4 @@ if (!process.env.WEBPACK_CLI_SKIP_IMPORT_LOCAL) {
2014

2115
process.title = "webpack";
2216

23-
runCLI(process.argv, originalModuleCompile);
17+
runCLI(process.argv);

packages/webpack-cli/lib/bootstrap.js

+1-3
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
11
const WebpackCLI = require("./webpack-cli");
22

3-
const runCLI = async (args, originalModuleCompile) => {
3+
const runCLI = async (args) => {
44
// Create a new instance of the CLI object
55
const cli = new WebpackCLI();
66

77
try {
8-
cli._originalModuleCompile = originalModuleCompile;
9-
108
await cli.run(args);
119
} catch (error) {
1210
cli.logger.error(error);

packages/webpack-cli/lib/webpack-cli.js

-15
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
const fs = require("fs");
22
const path = require("path");
33
const { pathToFileURL } = require("url");
4-
const Module = require("module");
54
const util = require("util");
65

76
const { program, Option } = require("commander");
@@ -244,21 +243,7 @@ class WebpackCLI {
244243
try {
245244
result = require(module);
246245
} catch (error) {
247-
let previousModuleCompile;
248-
249-
// TODO Workaround https://github.com/zertosh/v8-compile-cache/issues/30
250-
if (this._originalModuleCompile) {
251-
previousModuleCompile = Module.prototype._compile;
252-
253-
Module.prototype._compile = this._originalModuleCompile;
254-
}
255-
256246
const dynamicImportLoader = require("./utils/dynamic-import-loader")();
257-
258-
if (this._originalModuleCompile) {
259-
Module.prototype._compile = previousModuleCompile;
260-
}
261-
262247
if (
263248
(error.code === "ERR_REQUIRE_ESM" || process.env.WEBPACK_CLI_FORCE_LOAD_ESM_CONFIG) &&
264249
pathToFileURL &&

packages/webpack-cli/package.json

-1
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,6 @@
4040
"import-local": "^3.0.2",
4141
"interpret": "^2.2.0",
4242
"rechoir": "^0.7.0",
43-
"v8-compile-cache": "^2.2.0",
4443
"webpack-merge": "^5.7.3"
4544
},
4645
"peerDependencies": {

yarn.lock

+1-1
Original file line numberDiff line numberDiff line change
@@ -10814,7 +10814,7 @@ uuid@^3.3.2, uuid@^3.3.3, uuid@^3.4.0:
1081410814
resolved "https://registry.yarnpkg.com/uuid/-/uuid-3.4.0.tgz#b23e4358afa8a202fe7a100af1f5f883f02007ee"
1081510815
integrity sha512-HjSDRw6gZE5JMggctHBcjVak08+KEVhSIiDzFnT9S9aegmp85S/bReBVTb4QTFaRNptJ9kuYaNhnbNEOkbKb/A==
1081610816

10817-
v8-compile-cache@^2.0.3, v8-compile-cache@^2.2.0:
10817+
v8-compile-cache@^2.0.3:
1081810818
version "2.3.0"
1081910819
resolved "https://registry.yarnpkg.com/v8-compile-cache/-/v8-compile-cache-2.3.0.tgz#2de19618c66dc247dcfb6f99338035d8245a2cee"
1082010820
integrity sha512-l8lCEmLcLYZh4nbunNZvQCJc5pv7+RCwa8q/LdUx8u7lsWvPDKmpodJAJNwkAhJC//dFY48KuIEmjtd4RViDrA==

0 commit comments

Comments
 (0)