Registry / web-framework / babel-plugin-transform-replace-object-assign

babel-plugin-transform-replace-object-assign

JSON →
library2.0.0jsnpmunverified

This Babel plugin replaces all `Object.assign` calls with a custom implementation specified via the `moduleSpecifier` option, importing the shim from an npm package. At version 2.0.0 (latest release, last updated in 2018), the plugin requires `@babel/core@^7.0.0` as a peer dependency. It is similar to `babel-plugin-transform-object-assign` but allows using an external package (e.g., `object-assign`) instead of Babel's internal `_extends` helper, reducing bundle size by avoiding per-file function declarations. However, the plugin is explicitly deprecated by the author: the original Chrome bug it addressed (V8 issue #4118) has been fixed since Chrome 49. The plugin remains functional but is discouraged for new projects; developers should consider native `Object.assign` or `babel-plugin-transform-object-assign` instead.

npm install babel-plugin-transform-replace-object-assign
INSTALL
IMPORT
SIG · BABEL-PLUGIN-TRANS
B
babel-plugin-transform-replace-object-assign
web-frameworkjavascriptv2.0.0
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.

transform-replace-object-assign
plugins: [["transform-replace-object-assign", { "moduleSpecifier": "object-assign" }]]
plugins: ["transform-replace-object-assign"] (will use default moduleSpecifier, but may not be intended)
Add to Babel config as a plugin; the option `moduleSpecifier` is optional and defaults to "object-assign". No direct JavaScript import needed.
object-assign (runtime package)
npm install --save object-assign
npm install --save-dev object-assign (should be regular dependency if used at runtime)
The implementation package is imported at build time; ensure it is in dependencies.
object-assign (import in output)
import _objectAssign from 'object-assign';
import _objectAssign from 'object-assign'; (no common mistake, but output is auto-generated)
Output uses ESM import; compatible with bundlers. No manual import required.

Install the plugin and a custom Object.assign implementation, configure Babel, and see how Object.assign is replaced with an import of the custom package.

// Install npm install --save-dev @babel/core babel-plugin-transform-replace-object-assign npm install --save object-assign // .babelrc { "plugins": [ ["transform-replace-object-assign", { "moduleSpecifier": "object-assign" }] ] } // Input: src/index.js Object.assign({}, { foo: 'bar' }); // Build output (after Babel transform): import _objectAssign from 'object-assign'; _objectAssign({}, { foo: 'bar' }); // Note: Default option is { "moduleSpecifier": "object-assign" } so config can be simplified to: { "plugins": ["transform-replace-object-assign"] }
Debug
Known issues
deprecatedPlugin explicitly deprecated by author: original Chrome bug (V8 #4118) fixed in Chrome 49, making plugin unnecessary for its original purpose. Author advises against use unless you have a specific need.
fix
Use native Object.assign (ES6) or babel-plugin-transform-object-assign if you need runtime shimming.
affects: >=0.0.0
gotchaThe moduleSpecifier option must be a package available at runtime; if omitted, defaults to 'object-assign', which must be installed as a dependency.
fix
Ensure the specified package is in your dependencies and correct.
affects: >=0.0.0
gotchaPlugin only replaces direct calls to Object.assign (e.g., Object.assign(a, b)) — not polyfills or re-assignments. Code that uses Object.assign as a value (e.g., var assign = Object.assign) will not be transformed.
fix
If you need to replace all uses, consider using a different approach like babel-plugin-transform-object-assign which uses the _extends helper.
affects: >=0.0.0
breakingMajor version 2.0.0 requires @babel/core ^7.0.0 (Babel 7) and is not compatible with Babel 6.
fix
If using Babel 6, stick with version 1.x of this plugin.
affects: ^2.0.0
deprecatedPlugin has not been updated since 2018 — no fix for potential future Babel core changes.
fix
Consider alternatives like babel-plugin-transform-object-assign or @babel/plugin-transform-object-assign (Babel 7 core).
affects: >=2.0.0
Errors
Common errors & fixes
Error: Could not find plugin "transform-replace-object-assign". Ensure there is an entry in ./node_modules/babel-plugin-transform-replace-object-assign
Plugin not installed or not listed correctly in Babel config.
fix
Run: npm install --save-dev babel-plugin-transform-replace-object-assign
Error: Cannot find module 'object-assign'
Default moduleSpecifier 'object-assign' not installed as a runtime dependency.
fix
Run: npm install --save object-assign
TypeError: Object(...) is not a function (or similar at runtime if object-assign not imported properly)
Plugin transforms code but the custom assign package is not available at runtime because it's only in devDependencies or missing.
fix
Ensure the moduleSpecifier package is in dependencies, not devDependencies.
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies
@babel/corerequiredPeer dependency: required as the Babel environment for the plugin to run.
Agent activity
12 hits · last 30 days
node
10
OpenAI (training)
1
Resources