Skip to content

Commit

Permalink
Disable "Reentrant plugin detected" error in async mode (#14153)
Browse files Browse the repository at this point in the history
  • Loading branch information
nicolo-ribaudo committed Jan 14, 2022
1 parent ab2c578 commit 8035ad9
Showing 1 changed file with 19 additions and 9 deletions.
28 changes: 19 additions & 9 deletions packages/babel-core/src/config/files/plugins.ts
Expand Up @@ -6,6 +6,7 @@ import buildDebug from "debug";
import path from "path";
import type { Handler } from "gensync";
import loadCjsOrMjsDefault from "./module-types";
import { isAsync } from "../../gensync-utils/async";

import { createRequire } from "module";
const require = createRequire(import.meta.url);
Expand Down Expand Up @@ -149,18 +150,25 @@ function resolveStandardizedName(
}
}

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

try {
LOADING_MODULES.add(name);
if (!process.env.BABEL_8_BREAKING) {
LOADING_MODULES.add(name);
}
return yield* loadCjsOrMjsDefault(
name,
`You appear to be using a native ECMAScript module ${type}, ` +
Expand All @@ -175,6 +183,8 @@ function* requireModule(type: string, name: string): Handler<unknown> {
err.message = `[BABEL]: ${err.message} (While processing: ${name})`;
throw err;
} finally {
LOADING_MODULES.delete(name);
if (!process.env.BABEL_8_BREAKING) {
LOADING_MODULES.delete(name);
}
}
}

0 comments on commit 8035ad9

Please sign in to comment.