Make @swc/core as a peer dependency
Related plugins
-
[ ] plugin-react
-
[x] plugin-react-swc
-
[ ] plugin-react-oxc
-
[ ] plugin-rsc
Describe the bug
@swc/core doesn't follow semver but vite-plugin-react is using caret version.
This could silently break when plugin-react-swc is packaged together with swc plugins.
For example, @swc/[email protected] is only compatible with @swc/plugin-emotion@^11
(https://plugins.swc.rs/versions/range/426)
but the caret ^1.13.5 installs latest version on fresh install which breaks plugin compatibility.
To fix this we have to override the version or modify the lockfile manually which is not a great experience.
There could be two options:
- fix the version
- make it as a peer dependency
I think latter one makes more sense since swc's javascript interface is mostly consistent.
Related code
https://github.com/vitejs/vite-plugin-react/blob/main/packages/plugin-react-swc/package.json
Used Package Manager
yarn
Logs
No response
Validations
- [x] Follow our Code of Conduct
- [x] Read the Contributing Guidelines.
- [x] Read the docs.
- [x] Check that there isn't already an issue that reports the same bug to avoid creating a duplicate.
- [x] Make sure this is a Vite issue and not a framework-specific issue.
- [x] Check that this is a concrete bug. For Q&A open a GitHub Discussion or join our Discord Chat Server.
- [x] The provided reproduction is a minimal reproducible example of the bug.
Yeah given the instability of the plugin system of SWC, I think it would be better to give back control on the SWC version given that package override is not trivial. I opened https://github.com/vitejs/vite-plugin-react-swc/pull/206 a long time ago (before repo were merged) but I was never really happy about it so it was never merged. This would be a breaking change to ask users to install swc themself, but we can consider it in the next major (if we do one for Vite 8 for ex.)
It seems SWC made the plugins forward-compatible in the latest version (v1.15.0). https://blog.swc.rs/2025-11-4-wasm-backward-compatibility
So I guess after the next version of plugin-swc, we won't have this problem anymore.
Wow what a change, pain for an eternity finally resolved 🥲