From 7bf67ba2f6d6839f9769ebac23a10860ff110765 Mon Sep 17 00:00:00 2001 From: "opensearch-trigger-bot[bot]" <98922864+opensearch-trigger-bot[bot]@users.noreply.github.com> Date: Fri, 11 Aug 2023 13:45:30 +0800 Subject: [PATCH] Fix `exports is undefined` (#826) (#841) * Add allowTopLevelThis=true option for @babel/plugin-transform-modules-commonjs * remove override babel.config.js for build --------- (cherry picked from commit be25b8bd3b1c77865e1414aad215e645bc161711) Signed-off-by: Hailong Cui Signed-off-by: github-actions[bot] Co-authored-by: github-actions[bot] (cherry picked from commit 639df0d996cbf0c2546ff3bf1e78122c5ede60e0) --- babel.config.js | 21 ++++++++++++++------- 1 file changed, 14 insertions(+), 7 deletions(-) diff --git a/babel.config.js b/babel.config.js index 21b7ac48c..1d9ebbecf 100644 --- a/babel.config.js +++ b/babel.config.js @@ -5,11 +5,18 @@ // babelrc doesn't respect NODE_PATH anymore but using require does. // Alternative to install them locally in node_modules -module.exports = { - presets: [require("@babel/preset-env"), require("@babel/preset-react"), require("@babel/preset-typescript")], - plugins: [ - [require("@babel/plugin-transform-runtime"), { regenerator: true }], - require("@babel/plugin-proposal-class-properties"), - require("@babel/plugin-proposal-object-rest-spread"), - ], +module.exports = function (api) { + // ensure env is test so that this config won't impact build or dev server + if (api.env("test")) { + return { + presets: [require("@babel/preset-env"), require("@babel/preset-react"), require("@babel/preset-typescript")], + plugins: [ + [require("@babel/plugin-transform-runtime"), { regenerator: true }], + require("@babel/plugin-proposal-class-properties"), + require("@babel/plugin-proposal-object-rest-spread"), + [require("@babel/plugin-transform-modules-commonjs"), { allowTopLevelThis: true }], + ], + }; + } + return {}; };