esbuild-plugin-decorators
raw JSON →esbuild-plugin-decorators (v0.0.3) is an esbuild plugin that enables support for experimental ECMAScript decorators. It patches the esbuild build process to transform decorators using the TypeScript compiler API. This plugin is intended for projects that rely on legacy decorator syntax (e.g., from TypeScript's experimentalDecorators or Babel) and need to bundle with esbuild, which does not natively support decorators. The plugin is minimal and has no dependencies beyond esbuild and TypeScript. However, it is experimental and not actively maintained; the latest version (0.0.3) was released in early 2023. Compared to alternatives like esbuild-plugin-babel or esbuild-plugin-typescript-decorators, this one is a lightweight wrapper but lacks comprehensive error handling and documentation. Use with caution in production.
Common errors
error Error: Cannot find module 'esbuild-plugin-decorators' ↓
error Error: Decorators are not enabled. Set 'experimentalDecorators': true in tsconfig.json ↓
error TypeError: decoratorsPlugin is not a function ↓
error Plugin error: esbuild version mismatch ↓
Warnings
gotcha Plugin requires esbuild to be installed as a peer dependency. Not auto-installed. ↓
gotcha Plugin requires TypeScript compiler API (typescript package) for transformation. Ensure tsconfig has experimentalDecorators: true. ↓
deprecated The plugin is currently at version 0.0.3 with no updates since 2023. It may not work with newer esbuild versions. ↓
gotcha The plugin does not handle source maps properly; decorator-transformed code may have incorrect source mappings. ↓
gotcha Only works with ES modules (import/export). Does not support CommonJS modules for the input files. ↓
Install
npm install esbuild-plugin-decorators yarn add esbuild-plugin-decorators pnpm add esbuild-plugin-decorators Imports
- default wrong
const decoratorsPlugin = require('esbuild-plugin-decorators')correctimport decoratorsPlugin from 'esbuild-plugin-decorators' - decoratorsPlugin wrong
import { decoratorsPlugin } from 'esbuild-plugin-decorators'correctimport decoratorsPlugin from 'esbuild-plugin-decorators' - apply decorators wrong
esbuild.build({ plugins: [decoratorsPlugin] })correctesbuild.build({ plugins: [decoratorsPlugin()] })
Quickstart
import esbuild from 'esbuild';
import decoratorsPlugin from 'esbuild-plugin-decorators';
await esbuild.build({
entryPoints: ['src/index.ts'],
outfile: 'dist/bundle.js',
bundle: true,
plugins: [decoratorsPlugin()],
tsconfig: './tsconfig.json', // ensure experimentalDecorators: true
});