babel-plugin-transform-builtin-extend
raw JSON → 1.1.2 verified Sat Apr 25 auth: no javascript deprecated
A Babel 6 plugin that enables extending built-in JavaScript types like Error and Array, which require special handling due to their native constructor behavior. It uses static analysis to detect class extensions of globals you specify, optionally with an approximate mode for IE <= 10. This plugin is a specialized tool for a now-legacy Babel version (6.x) and has been superseded by native class support in modern JavaScript and Babel 7+. No active maintenance since 2016.
Common errors
error Error: Cannot find module 'babel-plugin-transform-builtin-extend' ↓
cause Plugin not installed or used with Babel 7+ (which uses @babel scoped packages).
fix
npm install babel-plugin-transform-builtin-extend --save-dev and ensure Babel 6 is used.
error ReferenceError: __proto__ is not defined ↓
cause Code runs in an environment where __proto__ is not supported (e.g., IE <= 10).
fix
Enable the 'approximate' option in plugin config, with caveats.
Warnings
deprecated This plugin is for Babel 6 only. Babel 7+ has native support for extending built-ins via @babel/plugin-proposal-class-properties or @babel/plugin-transform-classes. ↓
fix Upgrade to Babel 7+ and use appropriate modern plugins.
gotcha The 'approximate' mode for IE <= 10 does not correctly implement built-in extension semantics; it falls back to ES5 inheritance which may not work as expected. ↓
fix Avoid using approximate mode unless targeting legacy browsers and understand the limitations.
gotcha Static property inheritance relies on __proto__, which is not supported in IE <= 10 and some older browsers. ↓
fix Do not rely on static inheritance from extended built-ins if targeting IE <= 10.
Install
npm install babel-plugin-transform-builtin-extend yarn add babel-plugin-transform-builtin-extend pnpm add babel-plugin-transform-builtin-extend Imports
- plugin (default) wrong
Using require('babel-plugin-transform-builtin-extend') in codecorrectIn .babelrc: ["babel-plugin-transform-builtin-extend", { globals: ["Error", "Array"] }]
Quickstart
{
"plugins": [
["babel-plugin-transform-builtin-extend", {
"globals": ["Error", "Array"],
"approximate": false
}]
]
}