Registry /
web-framework / babel-plugin-transform-decorators-legacy
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
muslnode 18–226 runs
build_error
glibcnode 18–226 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']
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.
fixInstall 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.
fixReorder 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.
fixEnsure babel-core version 6.x is installed and use the short plugin name 'transform-decorators-legacy'.
Audit
Dependencies
babel-corerequiredRequires Babel 6.x as a peer dependency