Registry /
devops / babel-plugin-transform-class-constructor-call
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
✓ // .babelrc
{ "plugins": ["transform-class-constructor-call"] }
✗ npm install --save-dev babel-plugin-transform-class-constructor-call
The plugin is a Babel plugin, not a direct JavaScript import. Use it via Babel configuration.
require('babel-core')
✓ const babel = require('babel-core');
babel.transform(code, { plugins: ['transform-class-constructor-call'] });
✗ import { transform } from 'babel-core'; // Babel v6 uses CommonJS, not ESM
Babel v6's core package is 'babel-core' (not @babel/core) and uses CommonJS. Using ESM imports may fail.
class with call constructor
✓ class Point {
constructor(x, y) { this.x = x; this.y = y; }
call constructor(x, y) { return new Point(x, y); }
}
✗ // No call constructor; this is the only valid syntax for this plugin
The 'call constructor' syntax is non-standard and only works with this plugin. It is not part of any ES spec.
Demonstrates usage of the deprecated call constructor plugin to allow a class to be callable without 'new'.
// Install: npm install --save-dev babel-plugin-transform-class-constructor-call
// .babelrc
{
"plugins": ["transform-class-constructor-call"]
}
// Example usage in code.js
class Date {
constructor() {
this.date = new Date();
}
call constructor() {
let date = new Date();
return date.toString();
}
}
let now = new Date(); // instance
let nowStr = Date(); // string
console.log(now instanceof Date); // true
console.log(typeof nowStr); // 'string'
// Transpile with Babel CLI:
// npx babel code.js --out-file compiled.js
Errors
Common errors & fixes
Error: Plugin transform-class-constructor-call is deprecated
The plugin is deprecated and Babel may warn about it.
fixRemove the plugin from configuration and refactor code.
Error: Cannot find module 'babel-core'
Using npm packages for Babel v7 (e.g., @babel/core) instead of v6 (babel-core).
fixEnsure 'babel-core' (v6) is installed: npm install --save-dev babel-core
SyntaxError: Unexpected token
Attempting to use the call constructor syntax without the plugin enabled or with a different Babel version.
fixAdd this plugin to your Babel v6 configuration. For Babel v7, this syntax cannot be used.
Audit
Dependencies
@babel/corerequiredRequires Babel core v6 to load and run the plugin; not compatible with Babel v7+.