vite-plugin-react icon indicating copy to clipboard operation
vite-plugin-react copied to clipboard

Make @swc/core as a peer dependency

Open ha1fstack opened this issue 3 months ago • 3 comments

Related plugins

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

ha1fstack avatar Nov 11 '25 08:11 ha1fstack

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.)

ArnaudBarre avatar Nov 11 '25 21:11 ArnaudBarre

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.

sapphi-red avatar Nov 14 '25 02:11 sapphi-red

Wow what a change, pain for an eternity finally resolved 🥲

ha1fstack avatar Nov 14 '25 08:11 ha1fstack