Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Disable "Reentrant plugin detected" error in async mode #14153

Merged
merged 1 commit into from Jan 14, 2022
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
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);
}
}
}