{"id":19219,"library":"babel-plugin-transform-replace-object-assign","title":"babel-plugin-transform-replace-object-assign","description":"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.","status":"deprecated","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/newoga/babel-plugin-transform-replace-object-assign","tags":["javascript","assign","babel","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-transform-replace-object-assign","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-replace-object-assign","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-replace-object-assign","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency: required as the Babel environment for the plugin to run.","package":"@babel/core","optional":false}],"imports":[{"note":"Add to Babel config as a plugin; the option `moduleSpecifier` is optional and defaults to \"object-assign\". No direct JavaScript import needed.","wrong":"plugins: [\"transform-replace-object-assign\"] (will use default moduleSpecifier, but may not be intended)","symbol":"transform-replace-object-assign","correct":"plugins: [[\"transform-replace-object-assign\", { \"moduleSpecifier\": \"object-assign\" }]]"},{"note":"The implementation package is imported at build time; ensure it is in dependencies.","wrong":"npm install --save-dev object-assign (should be regular dependency if used at runtime)","symbol":"object-assign (runtime package)","correct":"npm install --save object-assign"},{"note":"Output uses ESM import; compatible with bundlers. No manual import required.","wrong":"import _objectAssign from 'object-assign'; (no common mistake, but output is auto-generated)","symbol":"object-assign (import in output)","correct":"import _objectAssign from 'object-assign';"}],"quickstart":{"code":"// Install\nnpm install --save-dev @babel/core babel-plugin-transform-replace-object-assign\nnpm install --save object-assign\n\n// .babelrc\n{\n  \"plugins\": [\n    [\"transform-replace-object-assign\", { \"moduleSpecifier\": \"object-assign\" }]\n  ]\n}\n\n// Input: src/index.js\nObject.assign({}, { foo: 'bar' });\n\n// Build output (after Babel transform):\nimport _objectAssign from 'object-assign';\n_objectAssign({}, { foo: 'bar' });\n\n// Note: Default option is { \"moduleSpecifier\": \"object-assign\" } so config can be simplified to:\n{\n  \"plugins\": [\"transform-replace-object-assign\"]\n}","lang":"javascript","description":"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."},"warnings":[{"fix":"Use native Object.assign (ES6) or babel-plugin-transform-object-assign if you need runtime shimming.","message":"Plugin 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.","severity":"deprecated","affected_versions":">=0.0.0"},{"fix":"Ensure the specified package is in your dependencies and correct.","message":"The moduleSpecifier option must be a package available at runtime; if omitted, defaults to 'object-assign', which must be installed as a dependency.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"If you need to replace all uses, consider using a different approach like babel-plugin-transform-object-assign which uses the _extends helper.","message":"Plugin 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.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"If using Babel 6, stick with version 1.x of this plugin.","message":"Major version 2.0.0 requires @babel/core ^7.0.0 (Babel 7) and is not compatible with Babel 6.","severity":"breaking","affected_versions":"^2.0.0"},{"fix":"Consider alternatives like babel-plugin-transform-object-assign or @babel/plugin-transform-object-assign (Babel 7 core).","message":"Plugin has not been updated since 2018 — no fix for potential future Babel core changes.","severity":"deprecated","affected_versions":">=2.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Run: npm install --save-dev babel-plugin-transform-replace-object-assign","cause":"Plugin not installed or not listed correctly in Babel config.","error":"Error: Could not find plugin \"transform-replace-object-assign\". Ensure there is an entry in ./node_modules/babel-plugin-transform-replace-object-assign"},{"fix":"Run: npm install --save object-assign","cause":"Default moduleSpecifier 'object-assign' not installed as a runtime dependency.","error":"Error: Cannot find module 'object-assign'"},{"fix":"Ensure the moduleSpecifier package is in dependencies, not devDependencies.","cause":"Plugin transforms code but the custom assign package is not available at runtime because it's only in devDependencies or missing.","error":"TypeError: Object(...) is not a function (or similar at runtime if object-assign not imported properly)"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}