Registry / web-framework / babel-plugin-transform-decorators-legacy

babel-plugin-transform-decorators-legacy

JSON →
library1.3.5jsnpmunverified

A Babel 6 plugin that replicates the legacy decorator behavior from Babel 5, allowing migration to Babel 6 without dropping decorators. Version 1.3.5 is the latest stable release; no longer maintained. For Babel 7+, use @babel/plugin-proposal-decorators with legacy: true. Key difference: decorators evaluate top-to-bottom and execute bottom-to-top (spec-compliant), unlike Babel 5's reverse order. Also handles static property initializers differently.

npm install babel-plugin-transform-decorators-legacy
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-decorators-legacy
web-frameworkjavascriptv1.3.5
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.

plugin
plugins: ["transform-decorators-legacy"]
plugins: ["babel-plugin-transform-decorators-legacy"]
In .babelrc or babel config, use the short plugin name without the 'babel-plugin-' prefix.
@babel/plugin-proposal-decorators (legacy)
plugins: [["@babel/plugin-proposal-decorators", { legacy: true }]]
plugins: ["@babel/plugin-proposal-decorators"]
For Babel 7+, use this official plugin with legacy: true to get the same behavior as transform-decorators-legacy.
require('babel-plugin-transform-decorators-legacy')
const plugin = require('babel-plugin-transform-decorators-legacy')
import plugin from 'babel-plugin-transform-decorators-legacy'
This plugin is intended for Babel 6 which uses CommonJS. ESM imports are not supported in Babel 6 context.

Shows correct Babel config, plugin ordering, and a simple decorator usage for logging.

// .babelrc { "plugins": ["transform-decorators-legacy"] } // Ensure order: decorators before class properties // Correct: { "plugins": [ "transform-decorators-legacy", "transform-class-properties" ] } // Example usage function log(target, name, descriptor) { const original = descriptor.value; descriptor.value = function(...args) { console.log(`Calling ${name} with`, args); return original.apply(this, args); }; return descriptor; } class Example { @log greet(name) { return `Hello, ${name}`; } } const ex = new Example(); ex.greet('World'); // logs: Calling greet with ['World']
Debug
Known issues
breakingBabel 7+ users must use @babel/plugin-proposal-decorators with legacy: true; this plugin does not work with Babel 7.
fix
Replace with @babel/plugin-proposal-decorators and set legacy: true in Babel config.
affects: >=1.0.0
gotchaPlugin ordering matters: transform-decorators-legacy must come before transform-class-properties.
fix
Place transform-decorators-legacy before transform-class-properties in the plugins array.
affects: >=1.0.0
deprecatedThis plugin is not maintained for Babel 6 and will not receive updates; the decorator proposal has evolved.
fix
Migrate to Babel 7 and use @babel/plugin-proposal-decorators with legacy: true or adopt the new decorator spec.
affects: >=1.0.0
gotchaDecorator evaluation order differs from Babel 5: later decorators evaluate first (top-to-bottom), but execute in reverse (bottom-to-top).
fix
Adjust code that depends on evaluation order; this behavior matches the spec.
affects: >=1.0.0
gotchaStatic class property initializers are evaluated once and cached; initializer returns precomputed value, not re-executed on each access.
fix
Do not rely on initializer being called multiple times for side effects.
affects: >=1.0.0
Errors
Common errors & fixes
Error: [BABEL] unknown: Decorators are not supported yet in 6.x.
Using Babel 6 without proper plugin enabled or using Babel 7's syntax without the plugin.
fix
Install babel-plugin-transform-decorators-legacy and add it to .babelrc plugins.
TypeError: Cannot read property 'value' of undefined
Incorrect plugin ordering: transform-class-properties runs before transform-decorators-legacy.
fix
Reorder plugins so transform-decorators-legacy comes first.
ReferenceError: [BABEL] unknown: Plugin/Preset files are not allowed to export objects, only functions.
Using an outdated Babel 6 version or incorrect import path.
fix
Ensure babel-core version 6.x is installed and use the short plugin name 'transform-decorators-legacy'.
Upgrade
Version history
1.3.5latest on npm
Audit
Dependencies
babel-corerequiredRequires Babel 6.x as a peer dependency
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources
babel-plugin-transform-decorators-legacy — npm install babel-plugin-transform-decorators-legacy · libregistry