{"id":19209,"library":"babel-plugin-transform-proto-to-assign","title":"babel-plugin-transform-proto-to-assign","description":"This Babel plugin transforms assignments to __proto__ into a shallow property copy, enabling prototype-like inheritance in environments that do not support __proto__ or Object.setPrototypeOf. The latest stable version is 6.26.0 (2017-01-30), part of Babel 6.x. It is maintained as part of the Babel monorepo but is considered legacy; Babel 7+ discourages use of this plugin and instead recommends using Object.setPrototypeOf or Object.create for performance reasons. The plugin does a shallow clone of all enumerable own properties from the target prototype. It works only with assignments like `obj.__proto__ = proto`, not `Object.setPrototypeOf`. It modifies Object.prototype, which can cause side effects. It is a single-purpose transform, not part of any preset-env. Alternative: use `@babel/plugin-transform-proto-to-assign` for Babel 7. The plugin is deprecated in favor of modern Object.setPrototypeOf.","status":"deprecated","version":"6.26.0","language":"javascript","source_language":"en","source_url":"https://github.com/babel/babel/tree/master/packages/babel-plugin-transform-proto-to-assign","tags":["javascript","babel-plugin"],"install":[{"cmd":"npm install babel-plugin-transform-proto-to-assign","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-proto-to-assign","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-proto-to-assign","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This plugin is designed for Babel 6's CommonJS module system. In Babel 6, plugins are loaded via require; ES import syntax may not work directly. For Babel 7, use @babel/plugin-transform-proto-to-assign.","wrong":"import p from 'babel-plugin-transform-proto-to-assign';","symbol":"default (plugin)","correct":"module.exports = require('babel-plugin-transform-proto-to-assign');"},{"note":"In Babel 6, plugins can be specified by package name string. Passing the plugin object directly also works but string is standard.","wrong":"require('babel-core').transform(code, { plugins: [require('babel-plugin-transform-proto-to-assign')] }); // may work but string name is preferred","symbol":"babel-core transform with plugin","correct":"require('babel-core').transform(code, { plugins: ['transform-proto-to-assign'] });"},{"note":"Babel automatically resolves the 'babel-plugin-' prefix, so either 'transform-proto-to-assign' or 'babel-plugin-transform-proto-to-assign' works.","wrong":"{\n  \"plugins\": [\"babel-plugin-transform-proto-to-assign\"]\n} // also valid, but shorter name without prefix is typical","symbol":".babelrc configuration","correct":"{\n  \"plugins\": [\"transform-proto-to-assign\"]\n}"}],"quickstart":{"code":"// Step 1: Install the plugin\n// npm install --save-dev babel-plugin-transform-proto-to-assign\n\n// Step 2: Create .babelrc with the plugin\n// {\n//   \"plugins\": [\"transform-proto-to-assign\"]\n// }\n\n// Step 3: Write source with __proto__ assignment\nvar foo = { a: 1 };\nvar bar = { b: 2 };\nbar.__proto__ = foo;\n\n// Step 4: Compile with Babel\n// npx babel script.js --out-file compiled.js\n\n// compiled.js output (simplified):\n// var _defaults = ...;\n// _defaults(bar, foo);\n\n// Note: Does not support dynamic prototype chain; only shallow copy of properties at assignment time.","lang":"javascript","description":"Shows installation, configuration, source code with __proto__ assignment, and compilation output."},"warnings":[{"fix":"Upgrade to Babel 7+ and install @babel/plugin-transform-proto-to-assign.","message":"This plugin is part of Babel 6 and has no active development. For Babel 7+, use '@babel/plugin-transform-proto-to-assign' instead.","severity":"deprecated","affected_versions":">=6.0.0"},{"fix":"Use Object.setPrototypeOf or Object.create for proper prototype chain if needed.","message":"The transform does a shallow copy of properties at the moment of assignment, not a live prototype chain. Changing the prototype later does not affect already-assigned properties.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Use explicit property assignment or Object.assign instead of __proto__ manipulation.","message":"Modifying Object.prototype can cause performance issues and side effects in other code. Avoid if possible.","severity":"gotcha","affected_versions":">=0.0.0"},{"fix":"Add a separate plugin or polyfill if supporting Object.setPrototypeOf is required.","message":"Only transforms assignments like `obj.__proto__ = value`. Does not handle Object.setPrototypeOf or Reflect.setPrototypeOf.","severity":"breaking","affected_versions":">=0.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-proto-to-assign' and ensure node_modules is present.","cause":"Plugin not installed or not in node_modules.","error":"Cannot find module 'babel-plugin-transform-proto-to-assign'"},{"fix":"Use '@babel/plugin-transform-proto-to-assign' instead, or downgrade to Babel 6.","cause":"Attempting to use the plugin with Babel 7 where the package name has changed.","error":"Error: Plugin .__proto__ is not a function"},{"fix":"Ensure the left-hand side of __proto__ assignment is an object.","cause":"Assigning to __proto__ on a non-object value (null/undefined).","error":"TypeError: Cannot set property __proto__ of undefined"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}