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

Revert Node.js 20.6.0 bug workaround #15965

Merged
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
51 changes: 0 additions & 51 deletions babel.config.js
Expand Up @@ -303,15 +303,6 @@ module.exports = function (api) {
].map(normalize),
plugins: [pluginImportMetaUrl],
},
// See comment in the plugin
convertESM && {
test: [
"./packages/babel-core/src/index.ts",
"./packages/babel-types/src/index.ts",
"./packages/babel-traverse/src/index.ts",
],
plugins: [pluginInjectErrorBugNode_20_6_0],
},
{
test: sources.map(source => normalize(source.replace("/src", "/test"))),
plugins: [
Expand Down Expand Up @@ -963,45 +954,3 @@ function pluginReplaceNavigator({ template }) {
},
};
}

// Workaround for https://github.com/nodejs/node/issues/49497, since
// Node.js is taking ages to release the fix.
// This bug only affects CJS packages that are imported from ESM. We only apply
// it to packages that have cycles in their entrypoint. They can be easily
// caught by our CI in ESM mode on Node.js 20.6.0:
// - @babel/core
// - @babel/types
// - @babel/traverse
//
// We will remove this workaround after one week that Node.js 20.6.1 has been
// released, so that all CIs using `node:latest` will be using the new version.
function pluginInjectErrorBugNode_20_6_0({ template }) {
const flag = "___internal__alreadyRunning";

return {
post({ path }) {
path.unshiftContainer(
"body",
// We use `"${flag}" + ""` so that the Node.js ESM-CJS
// integration does not detect it as an export.
template.statement.ast`
if (typeof process === "object" && process.version === "v20.6.0") {
if (exports["${flag}" + ""]) return;
Object.defineProperty(exports, "${flag}", {
value: true,
enumerable: false,
configurable: true,
});
}
`
);
path.pushContainer(
"body",
template.statement.ast`
if (typeof process === "object" && process.version === "v20.6.0")
delete exports["${flag}" + ""];
`
);
},
};
}