babel-plugin-object-assign

raw JSON →
1.2.1 verified Sat Apr 25 auth: no javascript deprecated

A Babel plugin for Babel 5.x that transforms Object.assign() calls into the internal extends helper, reducing the need for polyfills or libraries like _.extend. Version 1.2.1 is the current stable release, designed specifically for Babel 5 (babel-core >=5.6.0). It is a simple, focused plugin with no updates since 2015. Key differentiator: works at the AST level to replace Object.assign with a lightweight helper, avoiding runtime polyfills. Not compatible with Babel 6+.

error Cannot find module 'babel-plugin-object-assign'
cause Plugin not installed or Babel 6+ trying to resolve it incorrectly.
fix
Ensure you are using Babel 5 (babel-core@5) and have the plugin in node_modules. For Babel 6+, use @babel/plugin-transform-object-assign.
error TypeError: Cannot read property 'traverse' of undefined
cause Plugin loaded with newer Babel version that changed the API.
fix
Downgrade to Babel 5 or use a compatible replacement.
breaking Plugin only works with Babel 5.x (babel-core >=5.6.0). It is not compatible with Babel 6 or later versions.
fix Upgrade to a different approach: use @babel/plugin-transform-object-assign for Babel 7, or include a polyfill like core-js.
deprecated This plugin is deprecated and no longer maintained. Babel 5 itself has been superseded.
fix Migrate to Babel 7 and use @babel/plugin-transform-object-assign or @babel/preset-env with core-js.
gotcha The plugin replaces Object.assign only; it does not polyfill other Object methods or provide a full ES2015+ environment.
fix Combine with other Babel plugins or a polyfill for complete coverage.
gotcha When using browserify with babelify, the plugin must be specified as a string in the configure options; passing the plugin object directly may fail silently.
fix Use babelify.configure({ plugins: ['object-assign'] })
npm install babel-plugin-object-assign
yarn add babel-plugin-object-assign
pnpm add babel-plugin-object-assign

Demonstrates install, CLI usage, and programmatic transform with Babel 5.

// Install: npm install babel@5 babel-core@5 babel-plugin-object-assign
// Run: babel --plugins object-assign script.js

// Example script.js content before transformation:
const merged = Object.assign({ a: 1 }, { b: 2 });

// After transformation with the plugin:
// The output will use the internal extends helper instead of Object.assign.
// This ensures compatibility with older browsers without native Object.assign.

// Programmatic usage:
const babel = require('babel');
const result = babel.transform('const x = Object.assign({}, { y: 1 });', {
  plugins: ['object-assign']
});
console.log(result.code); // Output uses _extends helper