Registry / serialization / decorator-transforms

decorator-transforms

JSON →
library2.3.1jsnpmunverified

A Babel plugin that transforms JavaScript decorators (legacy TC39 stage 1) into simpler, smaller code using modern features like class static blocks, private fields, and WeakMap. Current stable version is 2.3.1, released December 2025, with minor/patch releases every few months. Key differentiators vs @babel/plugin-proposal-decorators: significantly smaller output, avoids transpiling other class features, built-in browser compatibility options. Supports both legacy and loose mode decorators, aims for bug-for-bug compatibility with Babel's legacy decorator transform. Includes a runtime helper for decorator initialization.

npm install decorator-transforms
INSTALL
IMPORT
SIG · DECORATOR-TRANSFOR
D
decorator-transforms
serializationjavascriptv2.3.1
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 18226 runs
build_error
glibc
node 18226 runs
build_error
Code
Verified usage

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

default (plugin)
plugins: ['module:decorator-transforms']
plugins: ['decorator-transforms']
Babel assumes 'decorator-transforms' means 'babel-plugin-decorator-transforms' due to naming convention; prefix with 'module:' to resolve correctly.
globals runtime
import 'decorator-transforms/globals'
import { globals } from 'decorator-transforms'
The globals module is a side-effect import that installs runtime helpers globally. Must be imported at the very beginning of your app.
runtime import path
import * as runtime from 'decorator-transforms/runtime'
import runtime from 'decorator-transforms/runtime'
The runtime module uses named exports; default import may not work in all bundlers.

Shows minimal Babel config with runEarly and runtime import, global runtime import at app entry, and a simple decorated class.

// babel.config.js module.exports = { plugins: [['module:decorator-transforms', { runtime: { import: require.resolve('decorator-transforms/runtime') }, runEarly: true }]] }; // app.js (entry point) import 'decorator-transforms/globals'; // example decorated class function log(target, key, descriptor) { const original = descriptor.value; descriptor.value = function(...args) { console.log(`Calling ${key} with`, args); return original.apply(this, args); }; return descriptor; } class MyClass { @log greet(name) { return `Hello, ${name}!`; } } const obj = new MyClass(); obj.greet('World'); // logs: Calling greet with ['World']
Debug
Known issues
gotchaDo not use 'decorator-transforms' directly as plugin name; prefix with 'module:' or use absolute path (require.resolve).
fix
Use 'module:decorator-transforms' or require.resolve('decorator-transforms') in plugins array.
affects: >=1.0.0
breakingv2.0.0 changed default runtime from 'import' to 'globals'; runEarly option introduced for broader browser compat.
fix
Add import 'decorator-transforms/globals' at app entry or set runtime: { import: ... } in config.
affects: >=2.0.0
gotchaIncompatible with @babel/plugin-proposal-decorators; do not use both simultaneously.
fix
Remove @babel/plugin-proposal-decorators from plugins when using decorator-transforms.
affects: >=1.0.0
gotcharunEarly: true requires extra babel traversal; only use if targeting browsers without native private fields/static blocks.
fix
Set runEarly: false (default) unless you need transpilation of private fields or static blocks.
affects: >=2.0.0
gotchaEmber classic builds: only 'globals' runtime option works because ember-auto-import cannot see transform output.
fix
Use runtime: 'globals' (default) and import 'decorator-transforms/globals' in app.js.
affects: >=1.0.0
Errors
Common errors & fixes
Module not found: Can't resolve 'decorator-transforms/globals'
Missing runtime import or incorrect import path.
fix
Ensure you have added import 'decorator-transforms/globals' at the very beginning of your entry file.
Plugin 'decorator-transforms' not found
Babel cannot resolve the plugin because the name convention expects 'babel-plugin-*' prefix.
fix
Use 'module:decorator-transforms' or require.resolve('decorator-transforms') in babel config.
Transform error: Decorator transform is not supported in this environment
Using decorator-transforms with incompatible Babel version or missing Babel peer dependencies.
fix
Ensure Babel 7.4+ is installed and that @babel/core is a peer dependency.
Upgrade
Version history
2.3.1latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
8 hits · last 30 days
node
8
Resources
decorator-transforms — npm install decorator-transforms · libregistry