ts-swc-rollup-plugin
raw JSON → 2.4.0 verified Mon Apr 27 auth: no javascript
A Rollup plugin that integrates swc (Speedy Web Compiler) for fast TypeScript/JavaScript transpilation leveraging ts-swc-transform. Current stable version is 2.4.0, with a maintenance release cadence. Key differentiators: performance-oriented alternative to @rollup/plugin-typescript or @rollup/plugin-babel; supports tsconfig resolution via get-tsconfig; ships TypeScript types; requires Node >=16. Suitable for bundling workflows that prioritize speed over full type-checking.
Common errors
error Cannot find module 'ts-swc-rollup-plugin' or its corresponding type declarations. ↓
cause Missing package install or incorrect TypeScript settings (e.g., no moduleResolution: 'node' or 'node16').
fix
npm install ts-swc-rollup-plugin --save-dev and ensure tsconfig.json has 'moduleResolution': 'node' or 'node16' (>= v2).
error Error: swc is not a function ↓
cause Using CommonJS require() with v2+ which is ESM-only.
fix
Use import swc from 'ts-swc-rollup-plugin' in an ES module context (type: 'module' in package.json or .mjs extension).
error TypeError: Cannot read properties of undefined (reading 'transform') ↓
cause Invalid or missing tsconfig causing ts-swc-transform to fail initialization.
fix
Ensure tsconfig.json exists and is valid JSON. Pass explicit tsconfig path: swc({ tsconfig: 'tsconfig.json' }).
Warnings
breaking Version 2.x requires Node >=16 and is ESM-only. CommonJS require() will fail. ↓
fix Update to Node >=16 and use import syntax. For CJS projects, consider dynamic import or use v1.x.
deprecated Passing tsconfig as a string path is deprecated in favor of using a resolved config object from get-tsconfig. ↓
fix Use getTsconfig() from get-tsconfig package: swc({ tsconfig: getTsconfig() }).
gotcha Plugin does not perform type checking; swc is a transpiler only. Use tsc --noEmit separately for type safety. ↓
fix Add a separate tsc --noEmit script to your build pipeline.
gotcha Options object is mutable; do not reuse the same options object across multiple Rollup builds. ↓
fix Create a fresh options object per build configuration.
Install
npm install ts-swc-rollup-plugin yarn add ts-swc-rollup-plugin pnpm add ts-swc-rollup-plugin Imports
- default wrong
const swc = require('ts-swc-rollup-plugin')correctimport swc from 'ts-swc-rollup-plugin' - RollupOptions.plugins wrong
export default { plugins: [swc({ tsconfig: 'tsconfig.json' })] }correctexport default { plugins: [swc({ tsconfig: 'tsconfig.json' })] } - type PluginOptions wrong
import { PluginOptions } from 'ts-swc-rollup-plugin'correctimport type { PluginOptions } from 'ts-swc-rollup-plugin'
Quickstart
// rollup.config.js
import swc from 'ts-swc-rollup-plugin';
process.env.SWC_ENV ??= process.env.NODE_ENV ?? 'development';
export default {
input: 'src/index.ts',
output: {
file: 'dist/bundle.js',
format: 'esm',
},
plugins: [
swc({
// Optional: defaults shown
cwd: process.cwd(),
tsconfig: 'tsconfig.json',
}),
],
};