From 055aa876e11df34b479ae75bc6485d02258682bc Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Nicol=C3=B2=20Ribaudo?= Date: Fri, 14 Jan 2022 11:27:54 +0100 Subject: [PATCH] Disable "Reentrant plugin detected" error in async mode --- .../babel-core/src/config/files/plugins.ts | 28 +++++++++++++------ 1 file changed, 19 insertions(+), 9 deletions(-) diff --git a/packages/babel-core/src/config/files/plugins.ts b/packages/babel-core/src/config/files/plugins.ts index f35432516099..cedcbadd4bae 100644 --- a/packages/babel-core/src/config/files/plugins.ts +++ b/packages/babel-core/src/config/files/plugins.ts @@ -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); @@ -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 { - 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}, ` + @@ -175,6 +183,8 @@ function* requireModule(type: string, name: string): Handler { 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); + } } }