Registry / web-framework / vite-plugin-swc-react

vite-plugin-swc-react

JSON →
library0.1.12jsnpmunverified

A Vite plugin that replaces Babel with SWC for fast React JSX transform, HMR, and optional polyfill/transpile via SWC's preset-env. Current version 0.1.12 has no recent updates; peer dependencies are @swc/core ^1.2.98 and Vite ^2.6.7+. It offers similar features to @vitejs/plugin-react but uses SWC for faster compilation. Differentiators include built-in polyfill mode and classic JSX runtime support. Release cadence is unknown (last update likely 2022).

npm install vite-plugin-swc-react
INSTALL
IMPORT
SIG · VITE-PLUGIN-SWC-RE
V
vite-plugin-swc-react
web-frameworkjavascriptv0.1.12
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

default
✓ import swcReact from 'vite-plugin-swc-react'
✗ const swcReact = require('vite-plugin-swc-react')
ESM-only; CommonJS require() will fail in Vite's ESM context.
swcReact
✓ import swcReact from 'vite-plugin-swc-react'
✗ const { swcReact } = require('vite-plugin-swc-react')
Package exports default export, not named.
type definitions
✓ import swcReact from 'vite-plugin-swc-react'
✗ import { VitePluginSwcReact } from 'vite-plugin-swc-react'
Types are attached to default export; no separate type export.

Configure Vite to use SWC for React JSX transform, replacing the default Babel-based plugin.

import { defineConfig } from 'vite'; import swcReact from 'vite-plugin-swc-react'; export default defineConfig({ plugins: [ swcReact() ] });
Debug
Known issues
breakingPackage is compatible only with Vite 2, not Vite 3+ or 4+. Installing on newer Vite versions will cause errors.
fix
Use @vitejs/plugin-react-swc or vite-plugin-swc-react-refresh instead, or downgrade Vite to ^2.6.7.
affects: >=0.1.0
gotchaHMR (React Refresh) is enabled by default but can be disabled via `reactFresh: false`. If HMR fails, try disabling it.
fix
Set swcReact({ reactFresh: false }) in plugin config.
affects: >=0.1.0
gotchaWhen using polyfill mode, you must install both `browserslist` (devDep) and `core-js` (dep) manually. Missing them causes runtime errors.
fix
Install npm install -D browserslist && npm install core-js
affects: >=0.1.0
Errors
Common errors & fixes
Error: The plugin 'vite:react-swc' is not compatible with Vite 3
Package only supports Vite 2 peer dep.
fix
Use @vitejs/plugin-react-swc for Vite 3+
Cannot find module 'core-js' or 'browserslist' while using polyfill
Missing required dependencies for polyfill mode.
fix
npm install core-js && npm install -D browserslist
Module parse failed: Unexpected token (1:14) - You may need an appropriate loader to handle this file type
JSX not transformed when plugin not properly configured or Vite version mismatch.
fix
Ensure vite-plugin-swc-react is added to plugins array and Vite version is 2.x.
Upgrade
Version history
0.1.12latest on npm
Audit
Dependencies
@swc/corerequiredRequired peer dependency for SWC compilation
viterequiredRequired peer dependency; only compatible with Vite 2
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
vite-plugin-swc-react — npm install vite-plugin-swc-react · libregistry