diff --git a/packages/react-scripts/config/webpack.config.js b/packages/react-scripts/config/webpack.config.js index 2b1b3bbd47d..951722beabd 100644 --- a/packages/react-scripts/config/webpack.config.js +++ b/packages/react-scripts/config/webpack.config.js @@ -351,7 +351,7 @@ module.exports = function (webpackEnv) { shouldUseSourceMap && { enforce: 'pre', exclude: /@babel(?:\/|\\{1,2})runtime/, - test: /\.(js|mjs|jsx|ts|tsx|css)$/, + test: /\.(js|mjs|cjs|jsx|ts|tsx|css)$/, loader: require.resolve('source-map-loader'), }, { @@ -412,7 +412,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: { @@ -464,7 +464,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: { @@ -592,7 +592,12 @@ 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? @@ -764,7 +769,7 @@ module.exports = function (webpackEnv) { !disableESLintPlugin && new ESLintPlugin({ // Plugin options - extensions: ['js', 'mjs', 'jsx', 'ts', 'tsx'], + extensions: ['js', 'mjs', 'cjs', 'jsx', 'ts', 'tsx'], formatter: require.resolve('react-dev-utils/eslintFormatter'), eslintPath: require.resolve('eslint'), failOnError: !(isEnvDevelopment && emitErrorsAsWarnings),