{"id":19207,"library":"babel-plugin-transform-object-hasown","title":"babel-plugin-transform-object-hasown","description":"Babel plugin for transforming Object.hasOwn() (ES2022 proposal) to a polyfill using Object.prototype.hasOwnProperty.call(). Current stable version: 1.1.0. Low release cadence, matches official polyfill behavior since v1.1.0. Key differentiator: targeted transform for the accessible Object.hasOwn proposal, only transforms exact 'Object.hasOwn' or 'Object[\"hasOwn\"]' patterns.","status":"active","version":"1.1.0","language":"javascript","source_language":"en","source_url":"https://github.com/niksy/babel-plugin-transform-object-hasown","tags":["javascript","babel","plugin","transform","object","hasown","object.hasown","hasownproperty"],"install":[{"cmd":"npm install babel-plugin-transform-object-hasown","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-transform-object-hasown","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-transform-object-hasown","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"Full npm package name required in .babelrc or babel.config.js.","wrong":"module.exports = { plugins: ['transform-object-hasown'] };","symbol":"plugin","correct":"module.exports = { plugins: ['babel-plugin-transform-object-hasown'] };"}],"quickstart":{"code":"// Install: npm install --save-dev babel-plugin-transform-object-hasown\n// .babelrc\n{\n  \"plugins\": [\"babel-plugin-transform-object-hasown\"]\n}\n\n// Input\nconst obj = {};\nif (Object.hasOwn(obj, 'prop')) {\n  console.log('has prop');\n}\n\n// Output: object.hasOwn replaced with a helper that uses Object.prototype.hasOwnProperty.call","lang":"javascript","description":"Shows installation, Babel config setup, and code transformation of Object.hasOwn() to a polyfill."},"warnings":[{"fix":"Always use Object.hasOwn or Object['hasOwn'] in source code.","message":"Only transforms exact patterns Object.hasOwn or Object['hasOwn'] — not Object['hasOwn']() with computed call or module aliases.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"If you need a shared polyfill, consider using @babel/polyfill or core-js.","message":"Uses a custom _objectHasOwn helper function; not a true runtime polyfill. The helper is defined per file, not shared.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Use with browserslist or @babel/preset-env to avoid unnecessary transforms.","message":"Plugin does not check for existing runtime polyfill; if Object.hasOwn is already natively supported, transform still applies.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-25T00:00:00.000Z","next_check":"2026-07-24T00:00:00.000Z","problems":[{"fix":"Ensure the plugin is added to your Babel config and the file is processed by Babel.","cause":"Plugin not configured or plugin is not transforming the code (maybe source file not processed by Babel).","error":"ReferenceError: _objectHasOwn is not defined"},{"fix":"Guard the call: if (obj != null && Object.hasOwn(obj, 'prop')) ...","cause":"Plugin's custom helper throws this error exactly as Object.hasOwn would — it's intentional, but may surprise developers expecting silent false.","error":"TypeError: Cannot convert undefined or null to object"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}