Skip to content

fix(swc): automatically unset env.targets when jsc.target is set#6886

Merged
chenjiahan merged 7 commits intomainfrom
set_jsc_target_0104
Jan 5, 2026
Merged

fix(swc): automatically unset env.targets when jsc.target is set#6886
chenjiahan merged 7 commits intomainfrom
set_jsc_target_0104

Conversation

@chenjiahan
Copy link
Copy Markdown
Member

Summary

This PR improves the compatibility between user-defined SWC options and Rsbuild's default configuration.

SWC does not allow jsc.target and env.targets to be configured simultaneously. Currently, Rsbuild provides a default env.targets based on Browserslist, which causes a conflict and throws an error if a user manually sets jsc.target in tools.swc.

This change adds a check during the SWC configuration merging process, if jsc.target is detected in user config, the built-in env.targets is automatically removed.

Checklist

  • Tests updated (or not required).
  • Documentation updated (or not required).

Copilot AI review requested due to automatic review settings January 4, 2026 14:19
@netlify
Copy link
Copy Markdown

netlify bot commented Jan 4, 2026

Deploy Preview for rsbuild ready!

Name Link
🔨 Latest commit 5bbfd63
🔍 Latest deploy log https://app.netlify.com/projects/rsbuild/deploys/695a7c533822d50008e81222
😎 Deploy Preview https://deploy-preview-6886--rsbuild.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.
Lighthouse
Lighthouse
1 paths audited
Performance: 68 (🟢 up 3 from production)
Accessibility: 100 (no change from production)
Best Practices: 100 (no change from production)
SEO: 100 (no change from production)
PWA: 60 (no change from production)
View the detailed breakdown and full score reports

To edit notification comments on pull requests, go to your Netlify project configuration.

Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

This PR resolves a configuration conflict between SWC's jsc.target and env.targets options. When users manually set jsc.target in their configuration, Rsbuild's default env.targets (derived from Browserslist) would conflict with it, causing SWC to throw an error. The fix automatically removes env.targets when jsc.target is detected after merging user config with defaults.

Key changes:

  • Modified the polyfill mode handling to use delete instead of setting mode to undefined
  • Added logic to detect jsc.target in merged config and automatically remove conflicting env.targets
  • Added E2E tests to validate the fix for both jsc.target configuration and SWC plugin usage

Reviewed changes

Copilot reviewed 12 out of 17 changed files in this pull request and generated 2 comments.

Show a summary per file
File Description
packages/core/src/plugins/swc.ts Core fix: Changed polyfill mode deletion to use delete operator; added conflict resolution logic to remove env.targets when jsc.target is set
packages/core/tests/snapshots/swc.test.ts.snap Updated snapshots to reflect removal of "mode": undefined entries in env config
packages/core/tests/snapshots/default.test.ts.snap Updated snapshots to reflect removal of "mode": undefined entries in env config
packages/core/tests/snapshots/environments.test.ts.snap Updated snapshots to reflect removal of "mode": undefined entries in env config
packages/core/tests/snapshots/builder.test.ts.snap Updated snapshots to reflect removal of "mode": undefined entries in env config
packages/plugin-babel/tests/snapshots/index.test.ts.snap Updated snapshots to reflect removal of "mode": undefined entries in env config
packages/plugin-react/tests/snapshots/index.test.ts.snap Updated snapshots to reflect removal of "mode": undefined entries in env config
packages/plugin-svelte/tests/snapshots/index.test.ts.snap Updated snapshots to reflect removal of "mode": undefined entries in env config
packages/plugin-svgr/tests/snapshots/index.test.ts.snap Updated snapshots to reflect removal of "mode": undefined entries in env config
e2e/cases/swc/jsc-target/* New E2E test to validate jsc.target configuration works correctly without conflicts
e2e/cases/swc/swc-plugin/* New E2E test to validate SWC WASM plugins work correctly
Files not reviewed (1)
  • pnpm-lock.yaml: Language not supported

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

chenjiahan and others added 2 commits January 4, 2026 22:36
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
@chenjiahan chenjiahan merged commit 38e1553 into main Jan 5, 2026
10 checks passed
@chenjiahan chenjiahan deleted the set_jsc_target_0104 branch January 5, 2026 00:20
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants