Skip to content

feat(webpack)!: remove SVGR option and provide withSvgr composable function#32843

Merged
jaysoo merged 11 commits intomasterfrom
NXC-3106
Sep 29, 2025
Merged

feat(webpack)!: remove SVGR option and provide withSvgr composable function#32843
jaysoo merged 11 commits intomasterfrom
NXC-3106

Conversation

@jaysoo
Copy link
Copy Markdown
Member

@jaysoo jaysoo commented Sep 24, 2025

BREAKING CHANGE: The svgr option has been removed from withReact, NxReactWebpackPlugin, and withNx (for Next.js). Projects that need SVGR support should now use the new withSvgr composable function from @nx/react.

For React webpack projects:

  • Import withSvgr from '@nx/react'
  • Add withSvgr() to your composePlugins chain after withReact()

For Next.js projects:

  • Add SVGR webpack configuration directly to your next.config.js

Migrations have been provided to automatically update existing configurations.

Closes NXC-3106

…nction

BREAKING CHANGE: The svgr option has been removed from withReact, NxReactWebpackPlugin, and withNx (for Next.js).
Projects that need SVGR support should now use the new withSvgr composable function from @nx/react.

For React webpack projects:
- Import withSvgr from '@nx/react'
- Add withSvgr() to your composePlugins chain after withReact()

For Next.js projects:
- Add SVGR webpack configuration directly to your next.config.js

Migrations have been provided to automatically update existing configurations.

🤖 Generated with [Claude Code](https://claude.ai/code)

Co-Authored-By: Claude <noreply@anthropic.com>
@jaysoo jaysoo requested review from a team, AgentEnder and FrozenPandaz as code owners September 24, 2025 19:21
@jaysoo jaysoo requested a review from Coly010 September 24, 2025 19:21
@vercel
Copy link
Copy Markdown

vercel Bot commented Sep 24, 2025

The latest updates on your projects. Learn more about Vercel for GitHub.

Project Deployment Preview Updated (UTC)
nx-dev Ready Ready Preview Sep 29, 2025 4:59pm

@nx-cloud
Copy link
Copy Markdown
Contributor

nx-cloud Bot commented Sep 24, 2025

View your CI Pipeline Execution ↗ for commit 27660f4

Command Status Duration Result
nx affected --targets=lint,test,test-kt,build,e... ✅ Succeeded 9m 24s View ↗
nx run-many -t check-imports check-commit check... ✅ Succeeded 2m 26s View ↗
nx-cloud record -- nx-cloud conformance:check ✅ Succeeded 2s View ↗
nx-cloud record -- nx format:check ✅ Succeeded 6s View ↗
nx-cloud record -- nx sync:check ✅ Succeeded 5s View ↗
nx documentation ✅ Succeeded 1m 47s View ↗

☁️ Nx Cloud last updated this comment at 2025-09-29 17:03:31 UTC

Copy link
Copy Markdown
Contributor

@nx-cloud nx-cloud Bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nx Cloud is proposing a fix for your failed CI:

We've updated the Next.js SVGR end-to-end tests to align with the breaking change that removes the nx.svgr option. The tests now use the new pattern where SVGR webpack configuration is added directly to the Next.js config via a withSvgr function, which matches the migration script output and ensures SVGR functionality continues to work as expected.

We verified this fix by re-running e2e-next:e2e-ci--src/next-svgr.test.ts.

Suggested Fix changes
diff --git a/e2e/next/src/next-svgr.test.ts b/e2e/next/src/next-svgr.test.ts
index c0531a1067..4b6176c5fc 100644
--- a/e2e/next/src/next-svgr.test.ts
+++ b/e2e/next/src/next-svgr.test.ts
@@ -54,14 +54,46 @@ describe('NextJs SVGR support', () => {
       `
       const { composePlugins, withNx } = require('@nx/next');
       const nextConfig = {
-        nx: {
-          svgr: true,
-        },
+        nx: {},
       };
       const plugins = [
         withNx,
       ];
-      module.exports = composePlugins(...plugins)(nextConfig);
+
+      // Add SVGR webpack config function
+      const withSvgr = (config) => {
+        // Add SVGR support
+        config.module.rules.push({
+          test: /\\.svg$/,
+          issuer: { not: /\\.(css|scss|sass)$/ },
+          resourceQuery: {
+            not: [
+              /__next_metadata__/,
+              /__next_metadata_route__/,
+              /__next_metadata_image_meta__/,
+            ],
+          },
+          use: [
+            {
+              loader: require.resolve('@svgr/webpack'),
+              options: {
+                svgo: false,
+                titleProp: true,
+                ref: true,
+              },
+            },
+            {
+              loader: require.resolve('file-loader'),
+              options: {
+                name: 'static/media/[name].[hash].[ext]',
+              },
+            },
+          ],
+        });
+        return config;
+      };
+      
+      module.exports = composePlugins(...plugins, withSvgr)(nextConfig);
     `
     );
 
@@ -116,18 +148,46 @@ describe('NextJs SVGR support', () => {
       `
       const { composePlugins, withNx } = require('@nx/next');
       const nextConfig = {
-        nx: {
-          svgr: {
-            svgo: false,
-            titleProp: true,
-            ref: true,
-          },
-        },
+        nx: {},
       };
       const plugins = [
         withNx,
       ];
-      module.exports = composePlugins(...plugins)(nextConfig);
+
+      // Add SVGR webpack config function
+      const withSvgr = (config) => {
+        // Add SVGR support
+        config.module.rules.push({
+          test: /\\.svg$/,
+          issuer: { not: /\\.(css|scss|sass)$/ },
+          resourceQuery: {
+            not: [
+              /__next_metadata__/,
+              /__next_metadata_route__/,
+              /__next_metadata_image_meta__/,
+            ],
+          },
+          use: [
+            {
+              loader: require.resolve('@svgr/webpack'),
+              options: {
+                svgo: false,
+                titleProp: true,
+                ref: true,
+              },
+            },
+            {
+              loader: require.resolve('file-loader'),
+              options: {
+                name: 'static/media/[name].[hash].[ext]',
+              },
+            },
+          ],
+        });
+        return config;
+      };
+      
+      module.exports = composePlugins(...plugins, withSvgr)(nextConfig);
     `
     );
 

❌ The fix was rejected.

Nx CloudView interactive diff ↗


⚙️ An Nx Cloud workspace admin can disable these reviews in workspace settings.

…default in SVGR migration

- Fixed AST selectors to be more specific using direct property access instead of :has() syntax
- Added support for require statements in addition to import statements
- Added support for export default in addition to module.exports
- Added test case for export default with NxReactWebpackPlugin
- Ensured withSvgr is properly inserted in composePlugins calls for withReact style
- Moved module.exports wrapping to use AST changes instead of string replacement

Related Issue(s)
Fixes NXC-3106
Added test coverage for ESM imports/export default, NxReactWebpackPlugin with svgr false, and NxReactWebpackPlugin with svgr options object

Related Issue(s)
Fixes NXC-3106
Grouped withReact and NxReactWebpackPlugin tests into separate describe blocks for better test organization and readability

Related Issue(s)
Fixes NXC-3106
Comment thread packages/next/src/migrations/update-22-0-0/add-svgr-to-next-config.ts Outdated
@jaysoo jaysoo merged commit 2e9b543 into master Sep 29, 2025
14 checks passed
@jaysoo jaysoo deleted the NXC-3106 branch September 29, 2025 17:49
jaysoo added a commit that referenced this pull request Sep 29, 2025
FrozenPandaz pushed a commit that referenced this pull request Sep 29, 2025
…sable function (#32843) (#32882)

This reverts commit 2e9b543. This is
meant for v22 not 21.6.
FrozenPandaz pushed a commit that referenced this pull request Sep 29, 2025
…sable function (#32843) (#32882)

This reverts commit 2e9b543. This is
meant for v22 not 21.6.
jaysoo added a commit that referenced this pull request Oct 1, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Oct 9, 2025

This pull request has already been merged/closed. If you experience issues related to these changes, please open a new issue referencing this pull request.

@github-actions github-actions Bot locked as resolved and limited conversation to collaborators Oct 9, 2025
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants