Skip to content

Commit 8035ad9

Browse files
Disable "Reentrant plugin detected" error in async mode (#14153)
1 parent ab2c578 commit 8035ad9

1 file changed

Lines changed: 19 additions & 9 deletions

File tree

packages/babel-core/src/config/files/plugins.ts

Lines changed: 19 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@ import buildDebug from "debug";
66
import path from "path";
77
import type { Handler } from "gensync";
88
import loadCjsOrMjsDefault from "./module-types";
9+
import { isAsync } from "../../gensync-utils/async";
910

1011
import { createRequire } from "module";
1112
const require = createRequire(import.meta.url);
@@ -149,18 +150,25 @@ function resolveStandardizedName(
149150
}
150151
}
151152

152-
const LOADING_MODULES = new Set();
153+
if (!process.env.BABEL_8_BREAKING) {
154+
// eslint-disable-next-line no-var
155+
var LOADING_MODULES = new Set();
156+
}
153157
function* requireModule(type: string, name: string): Handler<unknown> {
154-
if (LOADING_MODULES.has(name)) {
155-
throw new Error(
156-
`Reentrant ${type} detected trying to load "${name}". This module is not ignored ` +
157-
"and is trying to load itself while compiling itself, leading to a dependency cycle. " +
158-
'We recommend adding it to your "ignore" list in your babelrc, or to a .babelignore.',
159-
);
158+
if (!process.env.BABEL_8_BREAKING) {
159+
if (!(yield* isAsync()) && LOADING_MODULES.has(name)) {
160+
throw new Error(
161+
`Reentrant ${type} detected trying to load "${name}". This module is not ignored ` +
162+
"and is trying to load itself while compiling itself, leading to a dependency cycle. " +
163+
'We recommend adding it to your "ignore" list in your babelrc, or to a .babelignore.',
164+
);
165+
}
160166
}
161167

162168
try {
163-
LOADING_MODULES.add(name);
169+
if (!process.env.BABEL_8_BREAKING) {
170+
LOADING_MODULES.add(name);
171+
}
164172
return yield* loadCjsOrMjsDefault(
165173
name,
166174
`You appear to be using a native ECMAScript module ${type}, ` +
@@ -175,6 +183,8 @@ function* requireModule(type: string, name: string): Handler<unknown> {
175183
err.message = `[BABEL]: ${err.message} (While processing: ${name})`;
176184
throw err;
177185
} finally {
178-
LOADING_MODULES.delete(name);
186+
if (!process.env.BABEL_8_BREAKING) {
187+
LOADING_MODULES.delete(name);
188+
}
179189
}
180190
}

0 commit comments

Comments
 (0)