{"id":22873,"library":"vite-plugin-swc-transform","title":"vite-plugin-swc-transform","description":"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.","status":"active","version":"1.1.1","language":"javascript","source_language":"en","source_url":"https://github.com/ziir/vite-plugin-swc-transform","tags":["javascript","vite","plugin","vite-plugin","swc","transform","typescript","decorator","metadata"],"install":[{"cmd":"npm install vite-plugin-swc-transform","lang":"bash","label":"npm"},{"cmd":"yarn add vite-plugin-swc-transform","lang":"bash","label":"yarn"},{"cmd":"pnpm add vite-plugin-swc-transform","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"peer dependency: plugin hooks into Vite's build pipeline","package":"vite","optional":false}],"imports":[{"note":"Package is ESM-only; CommonJS require will fail.","wrong":"const swc = require('vite-plugin-swc-transform')","symbol":"default","correct":"import swc from 'vite-plugin-swc-transform'"},{"note":"Package exports only a default export.","wrong":"import { swc } from 'vite-plugin-swc-transform'","symbol":"swc","correct":"import swc from 'vite-plugin-swc-transform'"},{"note":"SwcOptions is a type; use import type or import { type SwcOptions }.","wrong":"import { SwcOptions } from 'vite-plugin-swc-transform'","symbol":"SwcOptions","correct":"import type { SwcOptions } from 'vite-plugin-swc-transform'"}],"quickstart":{"code":"import { defineConfig } from 'vite';\nimport swc from 'vite-plugin-swc-transform';\n\nexport default defineConfig({\n  plugins: [\n    swc({\n      swcOptions: {\n        jsc: {\n          target: 'es2022',\n          transform: {\n            legacyDecorator: true,\n            decoratorMetadata: true,\n            useDefineForClassFields: false,\n          },\n        },\n      },\n    }),\n  ],\n});","lang":"typescript","description":"Enables legacy decorators with metadata transformation using SWC in Vite build."},"warnings":[{"fix":"Migrate to TC39 stage 3 decorators when possible; use SWC's new decorator options.","message":"TypeScript legacy decorators (experimentalDecorators) are deprecated and will be removed in future TypeScript versions.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Set all needed SWC options in swcOptions; do not rely on tsconfig.json.","message":"Plugin ignores tsconfig.json; SWC options must be explicitly provided.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use import syntax or dynamic import(). Ensure project is configured for ESM.","message":"Package is ESM-only; require() will throw a runtime error.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Set 'useDefineForClassFields: false' (or true) explicitly, or set suppressLegacyDecoratorNoExplicitUDFCFWarning: true.","message":"When using legacyDecorator: true without an explicit useDefineForClassFields, a warning is emitted.","severity":"gotcha","affected_versions":">=0.2.0"},{"fix":"Add '@swc/helpers' to your project's dependencies.","message":"Using externalHelpers: true requires installing @swc/helpers as a dependency.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"For dev transformations, use SWC via Vite's esbuild or another plugin like vite-plugin-esbuild.","message":"The plugin transforms files only during build, not dev server middleware (HMR).","severity":"gotcha","affected_versions":">=0.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use import statement or dynamic import(). Ensure project type is 'module' in package.json.","cause":"Package is ESM-only but imported using require()","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module ... not supported."},{"fix":"Use import swc from 'vite-plugin-swc-transform' (no curly braces).","cause":"Attempting to import the default export as a named export","error":"TypeError: swc is not a function"},{"fix":"Set 'useDefineForClassFields' to false (or true) in swcOptions.jsc.transform.","cause":"legacyDecorator is true but useDefineForClassFields is not set","error":"Warning: SWC option 'jsc.transform.legacyDecorator' enabled without an explicit 'jsc.transform.useDefineForClassFields' value."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}