fix(swc): automatically unset env.targets when jsc.target is set#6886
Merged
chenjiahan merged 7 commits intomainfrom Jan 5, 2026
Merged
fix(swc): automatically unset env.targets when jsc.target is set#6886chenjiahan merged 7 commits intomainfrom
env.targets when jsc.target is set#6886chenjiahan merged 7 commits intomainfrom
Conversation
✅ Deploy Preview for rsbuild ready!
To edit notification comments on pull requests, go to your Netlify project configuration. |
Contributor
There was a problem hiding this comment.
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
deleteinstead of settingmodetoundefined - Added logic to detect
jsc.targetin merged config and automatically remove conflictingenv.targets - Added E2E tests to validate the fix for both
jsc.targetconfiguration 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.
Co-authored-by: Copilot <175728472+Copilot@users.noreply.github.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Summary
This PR improves the compatibility between user-defined SWC options and Rsbuild's default configuration.
SWC does not allow
jsc.targetandenv.targetsto be configured simultaneously. Currently, Rsbuild provides a defaultenv.targetsbased on Browserslist, which causes a conflict and throws an error if a user manually setsjsc.targetintools.swc.This change adds a check during the SWC configuration merging process, if
jsc.targetis detected in user config, the built-inenv.targetsis automatically removed.Checklist