esbuild-plugin-typescript-decorators
raw JSON → 0.1.0 verified Mon Apr 27 auth: no javascript
An ESBuild plugin that enables TypeScript decorator metadata emission (emitDecoratorMetadata) which ESBuild does not support natively. Version 0.1.0 is the initial release, with no further updates. It fills a gap for developers using ESBuild with decorators, as ESBuild skips type system features. This plugin ensures Reflect.getMetadata returns correct type information (e.g., design:type) during transpilation. It is a lightweight alternative to switching to tsc or ts-jest, but limited to emitDecoratorMetadata support only.
Common errors
error Error: [plugin: esbuild-decorators] Cannot find module 'typescript' ↓
cause Missing TypeScript as a peer dependency.
fix
Install typescript: npm install --save-dev typescript
error TypeError: esbuildDecorators is not a function ↓
cause Importing as default instead of named export or forgetting to call it.
fix
Use import { esbuildDecorators } from 'esbuild-plugin-typescript-decorators' and then in plugins: [esbuildDecorators()]
error Error: Reflect.getMetadata returns undefined even with plugin ↓
cause tsconfig.json missing emitDecoratorMetadata or experimentalDecorators.
fix
Set "experimentalDecorators": true and "emitDecoratorMetadata": true in tsconfig.
Warnings
gotcha ESBuild does not support decorators at all beyond basic transpilation; this plugin only adds emitDecoratorMetadata, not full decorator support (e.g., no proposal-stage decorators). ↓
fix Use a different tool like tsc or swc for full decorator support.
gotcha Plugin must be called as a function (esbuildDecorators()), not passed directly. ↓
fix Use esbuildDecorators() in plugins array.
deprecated Package has not been updated since v0.1.0; may not work with latest ESBuild versions (e.g., ESBuild v0.20+). ↓
fix Check compatibility; consider forking or using alternatives.
Install
npm install esbuild-plugin-typescript-decorators yarn add esbuild-plugin-typescript-decorators pnpm add esbuild-plugin-typescript-decorators Imports
- esbuildDecorators wrong
const esbuildDecorators = require('esbuild-plugin-typescript-decorators').esbuildDecoratorscorrectimport { esbuildDecorators } from 'esbuild-plugin-typescript-decorators' - esbuildDecorators (as plugin) wrong
plugins: [esbuildDecorators]correctplugins: [esbuildDecorators()] - esbuild wrong
const esbuild = require('esbuild')correctimport esbuild from 'esbuild'
Quickstart
import esbuild from 'esbuild'
import { esbuildDecorators } from 'esbuild-plugin-typescript-decorators'
await esbuild.build({
entryPoints: ['src/index.ts'],
outfile: 'dist/index.js',
bundle: true,
tsconfig: 'tsconfig.json', // must have "experimentalDecorators": true and "emitDecoratorMetadata": true
plugins: [
esbuildDecorators()
]
})