Registry / web-framework / esbuild-plugin-ts-decorators

esbuild-plugin-ts-decorators

JSON →
library1.0.3jsnpmunverified

An esbuild plugin that enables TypeScript's emitDecoratorMetadata support by transpiling decorated files with the TypeScript compiler. Version 1.0.3 is the latest and only stable release. It provides a lightweight, regex-based decorator detection and optional caching. Unlike alternatives like ts-jest or tsc compilation, this plugin integrates directly with esbuild's fast bundler, only reverting to tsc for files that contain decorators when emitDecoratorMetadata is enabled. Best suited for projects that need both esbuild's speed and TypeScript decorators with metadata reflection (e.g., NestJS, TypeORM, inversify).

npm install esbuild-plugin-ts-decorators
INSTALL
IMPORT
SIG · ESBUILD-PLUGIN-TS-
E
esbuild-plugin-ts-decorators
web-frameworkjavascriptv1.0.3
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

esbuildDecorators
import { esbuildDecorators } from 'esbuild-plugin-ts-decorators'
const esbuildDecorators = require('esbuild-plugin-ts-decorators')
Package ships TypeScript types; default export not available; named export only.
esbuild
import { build } from 'esbuild'
const { build } = require('esbuild')
esbuild is ESM-only starting from v0.12; CommonJS require may fail depending on module resolution.
Options
import type { Options } from 'esbuild-plugin-ts-decorators'
import { Options } from 'esbuild-plugin-ts-decorators'
Options type is exported but used only for TypeScript types; no runtime value.

Shows how to set up esbuild with esbuild-plugin-ts-decorators, including plugin options and TypeScript type usage.

import { build } from 'esbuild'; import { esbuildDecorators } from 'esbuild-plugin-ts-decorators'; async function buildWithDecorators() { const result = await build({ entryPoints: ['src/index.ts'], bundle: true, outfile: 'dist/index.js', platform: 'node', target: 'node14', tsconfig: 'tsconfig.json', plugins: [ esbuildDecorators({ tsconfig: 'tsconfig.json', cwd: process.cwd(), cache: true, tsx: false, }), ], }); console.log('Build successful'); } buildWithDecorators().catch(console.error);
Debug
Known issues
gotchaPlugin performance impact: all .ts files are processed by the plugin's regex to detect decorators, which adds overhead compared to plain esbuild builds.
fix
If performance is a concern, consider using alternative tools like tsc or ts-jest for decorator-heavy projects, or limit the plugin's scope with esbuild's plugin filters.
affects: >=1.0.0
gotchaCache behavior: when watch mode is off, cache defaults to false; you must set cache: true explicitly to enable caching.
fix
Set cache: true in plugin options if you want to avoid re-compiling unchanged decorated files on every build.
affects: >=1.0.0
deprecatedThe plugin relies on an unstable regex pattern for decorator detection; future TypeScript decorator syntax changes may break matching.
fix
Stay updated with plugin releases; consider using a more robust parser (e.g., TypeScript's AST) if regex fails.
affects: >=1.0.0
gotchaNot compatible with TypeScript's experimentalDecorators: false; plugin assumes experimental decorators are used.
fix
Ensure your tsconfig.json has "experimentalDecorators": true and "emitDecoratorMetadata": true.
affects: >=1.0.0
gotchaThe plugin only transpiles files that actually contain decorators; files without decorators are passed through esbuild as normal, so they won't have emitDecoratorMetadata.
fix
If a file uses decorators indirectly (e.g., re-exports), it may not be detected; manually include the file or set force: true to transpile all files.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: Cannot read properties of undefined (reading 'fileName')
The plugin expects a tsconfig path but it's not provided or the tsconfig is missing.
fix
Pass a valid tsconfig option: esbuildDecorators({ tsconfig: 'tsconfig.json' })
Error: The plugin 'esbuild-plugin-ts-decorators' must be used after the 'ts' plugin?
Order of plugins matters; the decorator plugin should come before other plugins that transform TypeScript.
fix
Ensure esbuildDecorators is the first plugin in the plugins array.
Module not found: Can't resolve 'esbuild-plugin-ts-decorators'
Package not installed or import path incorrect.
fix
Run npm install esbuild-plugin-ts-decorators --save-dev and verify the import statement: import { esbuildDecorators } from 'esbuild-plugin-ts-decorators'
Upgrade
Version history
1.0.3latest on npm
Audit
Dependencies
esbuildrequiredPeer dependency; plugin integrates as an esbuild plugin.
typescriptrequiredPeer dependency; used to transpile decorated files with correct emitDecoratorMetadata.
Agent activity
18 hits · last 30 days
node
14
OpenAI (training)
2
Amazon
1
Resources
esbuild-plugin-ts-decorators — npm install esbuild-plugin-ts-decorators · libregistry