diff --git a/.babelrc.js b/.babelrc.js index 9a6311a2c5..4a6d9dc764 100644 --- a/.babelrc.js +++ b/.babelrc.js @@ -46,7 +46,9 @@ module.exports = function(api) { "@babel/proposal-export-namespace-from", "@babel/proposal-numeric-separator", ["@babel/proposal-object-rest-spread", { useBuiltIns: true }], - convertESM ? "@babel/transform-modules-commonjs" : null, + + // Explicitly use the lazy version of CommonJS modules. + convertESM ? ["@babel/transform-modules-commonjs", { lazy: true }] : null, ].filter(Boolean), overrides: [ { @@ -56,6 +58,15 @@ module.exports = function(api) { ["@babel/transform-for-of", { assumeArray: true }], ], }, + { + test: "./packages/babel-register", + plugins: [ + // Override the root options to disable lazy imports for babel-register + // because otherwise the require hook will try to lazy-import things + // leading to dependency cycles. + convertESM ? "@babel/transform-modules-commonjs" : null, + ].filter(Boolean), + }, ], };