diff --git a/packages/react/plugins/nx-react-webpack-plugin/lib/apply-react-config.ts b/packages/react/plugins/nx-react-webpack-plugin/lib/apply-react-config.ts index 6527ac60c83d8..c12bb1507e717 100644 --- a/packages/react/plugins/nx-react-webpack-plugin/lib/apply-react-config.ts +++ b/packages/react/plugins/nx-react-webpack-plugin/lib/apply-react-config.ts @@ -101,7 +101,10 @@ function removeSvgLoaderIfPresent( config: Partial ) { const svgLoaderIdx = config.module.rules.findIndex( - (rule) => typeof rule === 'object' && rule.test.toString().includes('svg') + (rule) => + typeof rule === 'object' && + typeof rule.test !== 'undefined' && + rule.test.toString().includes('svg') ); if (svgLoaderIdx === -1) return; config.module.rules.splice(svgLoaderIdx, 1); diff --git a/packages/rspack/src/plugins/utils/apply-react-config.ts b/packages/rspack/src/plugins/utils/apply-react-config.ts index acd6edc4024ac..4d116cedc4de7 100644 --- a/packages/rspack/src/plugins/utils/apply-react-config.ts +++ b/packages/rspack/src/plugins/utils/apply-react-config.ts @@ -47,7 +47,7 @@ function removeSvgLoaderIfPresent( config: Partial ) { const svgLoaderIdx = config.module.rules.findIndex( - (rule) => typeof rule === 'object' && rule.test.toString().includes('svg') + (rule) => typeof rule === 'object' && rule.test?.toString().includes('svg') ); if (svgLoaderIdx === -1) return; config.module.rules.splice(svgLoaderIdx, 1);