{"id":21278,"library":"esbuild-plugin-ts-decorators","title":"esbuild-plugin-ts-decorators","description":"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).","status":"active","version":"1.0.3","language":"javascript","source_language":"en","source_url":"git@github.com:andreisergiu98/esbuild-plugin-ts-decorators","tags":["javascript","esbuild","decorators","typescript"],"install":[{"cmd":"npm install esbuild-plugin-ts-decorators","lang":"bash","label":"npm"},{"cmd":"yarn add esbuild-plugin-ts-decorators","lang":"bash","label":"yarn"},{"cmd":"pnpm add esbuild-plugin-ts-decorators","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; plugin integrates as an esbuild plugin.","package":"esbuild","optional":false},{"reason":"Peer dependency; used to transpile decorated files with correct emitDecoratorMetadata.","package":"typescript","optional":false}],"imports":[{"note":"Package ships TypeScript types; default export not available; named export only.","wrong":"const esbuildDecorators = require('esbuild-plugin-ts-decorators')","symbol":"esbuildDecorators","correct":"import { esbuildDecorators } from 'esbuild-plugin-ts-decorators'"},{"note":"esbuild is ESM-only starting from v0.12; CommonJS require may fail depending on module resolution.","wrong":"const { build } = require('esbuild')","symbol":"esbuild","correct":"import { build } from 'esbuild'"},{"note":"Options type is exported but used only for TypeScript types; no runtime value.","wrong":"import { Options } from 'esbuild-plugin-ts-decorators'","symbol":"Options","correct":"import type { Options } from 'esbuild-plugin-ts-decorators'"}],"quickstart":{"code":"import { build } from 'esbuild';\nimport { esbuildDecorators } from 'esbuild-plugin-ts-decorators';\n\nasync function buildWithDecorators() {\n  const result = await build({\n    entryPoints: ['src/index.ts'],\n    bundle: true,\n    outfile: 'dist/index.js',\n    platform: 'node',\n    target: 'node14',\n    tsconfig: 'tsconfig.json',\n    plugins: [\n      esbuildDecorators({\n        tsconfig: 'tsconfig.json',\n        cwd: process.cwd(),\n        cache: true,\n        tsx: false,\n      }),\n    ],\n  });\n  console.log('Build successful');\n}\n\nbuildWithDecorators().catch(console.error);","lang":"typescript","description":"Shows how to set up esbuild with esbuild-plugin-ts-decorators, including plugin options and TypeScript type usage."},"warnings":[{"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.","message":"Plugin performance impact: all .ts files are processed by the plugin's regex to detect decorators, which adds overhead compared to plain esbuild builds.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Set cache: true in plugin options if you want to avoid re-compiling unchanged decorated files on every build.","message":"Cache behavior: when watch mode is off, cache defaults to false; you must set cache: true explicitly to enable caching.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Stay updated with plugin releases; consider using a more robust parser (e.g., TypeScript's AST) if regex fails.","message":"The plugin relies on an unstable regex pattern for decorator detection; future TypeScript decorator syntax changes may break matching.","severity":"deprecated","affected_versions":">=1.0.0"},{"fix":"Ensure your tsconfig.json has \"experimentalDecorators\": true and \"emitDecoratorMetadata\": true.","message":"Not compatible with TypeScript's experimentalDecorators: false; plugin assumes experimental decorators are used.","severity":"gotcha","affected_versions":">=1.0.0"},{"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.","message":"The plugin only transpiles files that actually contain decorators; files without decorators are passed through esbuild as normal, so they won't have emitDecoratorMetadata.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Pass a valid tsconfig option: esbuildDecorators({ tsconfig: 'tsconfig.json' })","cause":"The plugin expects a tsconfig path but it's not provided or the tsconfig is missing.","error":"TypeError: Cannot read properties of undefined (reading 'fileName')"},{"fix":"Ensure esbuildDecorators is the first plugin in the plugins array.","cause":"Order of plugins matters; the decorator plugin should come before other plugins that transform TypeScript.","error":"Error: The plugin 'esbuild-plugin-ts-decorators' must be used after the 'ts' plugin?"},{"fix":"Run npm install esbuild-plugin-ts-decorators --save-dev and verify the import statement: import { esbuildDecorators } from 'esbuild-plugin-ts-decorators'","cause":"Package not installed or import path incorrect.","error":"Module not found: Can't resolve 'esbuild-plugin-ts-decorators'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}