From ef99ed95e13e2cf0ea8f98062c12ceff5e73735b Mon Sep 17 00:00:00 2001 From: Lyuben Deninski Date: Fri, 8 Jul 2022 23:50:44 +0300 Subject: [PATCH 1/2] Added the missed .cjs extension for forcing commonjs module type --- packages/react-scripts/config/webpack.config.js | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index e465d8e7a00..00d84a93d53 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -414,7 +414,7 @@ module.exports = function (webpackEnv) { // Process application JS with Babel. // The preset includes JSX, Flow, TypeScript, and some ESnext features. { - test: /\.(js|mjs|jsx|ts|tsx)$/, + test: /\.(js|mjs|cjs|jsx|ts|tsx)$/, include: paths.appSrc, loader: require.resolve('babel-loader'), options: { @@ -466,7 +466,7 @@ module.exports = function (webpackEnv) { // Process any JS outside of the app with Babel. // Unlike the application JS, we only compile the standard ES features. { - test: /\.(js|mjs)$/, + test: /\.(js|mjs|cjs)$/, exclude: /@babel(?:\/|\\{1,2})runtime/, loader: require.resolve('babel-loader'), options: { From 904e13eaab1cd39add63704c63e56e5e84fb16d5 Mon Sep 17 00:00:00 2001 From: Lyuben Deninski Date: Sat, 9 Jul 2022 01:26:33 +0300 Subject: [PATCH 2/2] Moved .cjs handling to webpack's intenal logic --- packages/react-scripts/config/webpack.config.js | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 00d84a93d53..e80784f15d1 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -414,7 +414,7 @@ module.exports = function (webpackEnv) { // Process application JS with Babel. // The preset includes JSX, Flow, TypeScript, and some ESnext features. { - test: /\.(js|mjs|cjs|jsx|ts|tsx)$/, + test: /\.(js|mjs|jsx|ts|tsx)$/, include: paths.appSrc, loader: require.resolve('babel-loader'), options: { @@ -466,7 +466,7 @@ module.exports = function (webpackEnv) { // Process any JS outside of the app with Babel. // Unlike the application JS, we only compile the standard ES features. { - test: /\.(js|mjs|cjs)$/, + test: /\.(js|mjs)$/, exclude: /@babel(?:\/|\\{1,2})runtime/, loader: require.resolve('babel-loader'), options: { @@ -594,7 +594,7 @@ module.exports = function (webpackEnv) { // its runtime that would otherwise be processed through "file" loader. // Also exclude `html` and `json` extensions so they get processed // by webpacks internal loaders. - exclude: [/^$/, /\.(js|mjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/], + exclude: [/^$/, /\.(js|mjs|cjs|jsx|ts|tsx)$/, /\.html$/, /\.json$/], type: 'asset/resource', }, // ** STOP ** Are you adding a new loader?