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

vite-plugin-swc-transform

JSON →
library1.1.1jsnpmunverified

Vite plugin to transform TypeScript/JavaScript source files with SWC during the build process. Current stable version is 1.1.1, released with support for Vite 5, 6, and 7. It provides sane defaults for legacy/experimental decorators and metadata, and gives full control over SWC configuration. Unlike esbuild (Vite's default), it supports TypeScript legacy decorators with metadata. ESM-only, ships TypeScript declarations, and requires Node >=18.

npm install vite-plugin-swc-transform
INSTALL
IMPORT
SIG · VITE-PLUGIN-SWC-TR
V
vite-plugin-swc-transform
web-frameworkjavascriptv1.1.1
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

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

default
✓ import swc from 'vite-plugin-swc-transform'
✗ const swc = require('vite-plugin-swc-transform')
Package is ESM-only; CommonJS require will fail.
swc
✓ import swc from 'vite-plugin-swc-transform'
✗ import { swc } from 'vite-plugin-swc-transform'
Package exports only a default export.
SwcOptions
✓ import type { SwcOptions } from 'vite-plugin-swc-transform'
✗ import { SwcOptions } from 'vite-plugin-swc-transform'
SwcOptions is a type; use import type or import { type SwcOptions }.

Enables legacy decorators with metadata transformation using SWC in Vite build.

import { defineConfig } from 'vite'; import swc from 'vite-plugin-swc-transform'; export default defineConfig({ plugins: [ swc({ swcOptions: { jsc: { target: 'es2022', transform: { legacyDecorator: true, decoratorMetadata: true, useDefineForClassFields: false, }, }, }, }), ], });
Debug
Known issues
deprecatedTypeScript legacy decorators (experimentalDecorators) are deprecated and will be removed in future TypeScript versions.
fix
Migrate to TC39 stage 3 decorators when possible; use SWC's new decorator options.
affects: >=0.0.0
gotchaPlugin ignores tsconfig.json; SWC options must be explicitly provided.
fix
Set all needed SWC options in swcOptions; do not rely on tsconfig.json.
affects: >=0.0.0
gotchaPackage is ESM-only; require() will throw a runtime error.
fix
Use import syntax or dynamic import(). Ensure project is configured for ESM.
affects: >=0.0.0
gotchaWhen using legacyDecorator: true without an explicit useDefineForClassFields, a warning is emitted.
fix
Set 'useDefineForClassFields: false' (or true) explicitly, or set suppressLegacyDecoratorNoExplicitUDFCFWarning: true.
affects: >=0.2.0
gotchaUsing externalHelpers: true requires installing @swc/helpers as a dependency.
fix
Add '@swc/helpers' to your project's dependencies.
affects: >=0.0.0
gotchaThe plugin transforms files only during build, not dev server middleware (HMR).
fix
For dev transformations, use SWC via Vite's esbuild or another plugin like vite-plugin-esbuild.
affects: >=0.0.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported.
Package is ESM-only but imported using require()
fix
Use import statement or dynamic import(). Ensure project type is 'module' in package.json.
TypeError: swc is not a function
Attempting to import the default export as a named export
fix
Use import swc from 'vite-plugin-swc-transform' (no curly braces).
Warning: SWC option 'jsc.transform.legacyDecorator' enabled without an explicit 'jsc.transform.useDefineForClassFields' value.
legacyDecorator is true but useDefineForClassFields is not set
fix
Set 'useDefineForClassFields' to false (or true) in swcOptions.jsc.transform.
Upgrade
Version history
1.1.1latest on npm
Audit
Dependencies
viterequiredpeer dependency: plugin hooks into Vite's build pipeline
Agent activity
11 hits · last 30 days
node
10
OpenAI (training)
1
Resources
vite-plugin-swc-transform — npm install vite-plugin-swc-transform · libregistry