{"id":24957,"library":"babel-plugin-remove-object-properties","title":"Babel Plugin Remove Object Properties","description":"Babel plugin for stripping object properties from AST nodes that match a supplied regex pattern. The current stable version is 1.0.2, released with low release cadence. It works during Babel's transpilation phase, removing nodes of type 'ObjectProperty' via regex. Unlike generic Babel visitors or AST manipulation utilities, this plugin provides a simple configurable approach to remove object properties (e.g., data-* attributes in React). Suitable for cleaning test attributes from production builds. Has minimal dependencies and is distributed on npm.","status":"active","version":"1.0.2","language":"javascript","source_language":"en","source_url":null,"tags":["javascript"],"install":[{"cmd":"npm install babel-plugin-remove-object-properties","lang":"bash","label":"npm"},{"cmd":"yarn add babel-plugin-remove-object-properties","lang":"bash","label":"yarn"},{"cmd":"pnpm add babel-plugin-remove-object-properties","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"This is a Babel plugin, not imported directly in application code.","wrong":"import babelPluginRemoveObjectProperties from 'babel-plugin-remove-object-properties'","symbol":"default","correct":"No import needed; configured via .babelrc or programmatic API."},{"note":"Without options array, the plugin may fail or not apply regex correctly.","wrong":"\"plugins\": [\"babel-plugin-remove-object-properties\"]","symbol":"plugin reference in .babelrc","correct":"\"plugins\": [[\"remove-object-properties\", { \"regexp\": \"data-*\" }]]"},{"note":"Must be nested inside plugins array as a tuple with options.","wrong":"require('babel-plugin-remove-object-properties')({ regexp: 'data-*' })","symbol":"programmatic usage","correct":"require('@babel/core').transform(code, { plugins: [[require('babel-plugin-remove-object-properties'), { regexp: 'data-*' }]] })"}],"quickstart":{"code":"// In .babelrc or babel.config.js\n// Remove all properties matching regex 'data-*'\n{\n  \"plugins\": [[\"remove-object-properties\", { \"regexp\": \"data-*\" }]]\n}\n\n// Before transpilation:\n<div data-id=\"test\">Hello</div>\n\n// After transpilation:\n<div>Hello</div>","lang":"javascript","description":"Configures Babel plugin to remove properties matching 'data-*' regex from JSX elements."},"warnings":[{"fix":"Use a proper regex like '^data-' to match keys starting with 'data-'.","message":"The regex is applied to the property key, not the entire property string. Ensure regex matches exactly the property name (e.g., 'data-*' matches 'data-' followed by any chars, but not 'data-test' without wildcard? Actually 'data-*' matching? Use '^data-' to be safe.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Restrict usage to specific files or conditions if unwanted removal occurs.","message":"Plugin removes all object properties matching the regex, including non-JSX object properties; be aware it's not limited to JSX attributes.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Test with your Babel version; consider using modern alternatives like babel-plugin-strip-sourcemap or custom visitor.","message":"The package has not been updated since 2017; may not work with Babel 7 or newer without adjustments.","severity":"deprecated","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-05-01T00:00:00.000Z","next_check":"2026-07-30T00:00:00.000Z","problems":[{"fix":"Use double array syntax: \"plugins\": [[\"remove-object-properties\", { \"regexp\": \"data-*\" }]]","cause":"Plugin not receiving options object correctly in .babelrc.","error":"TypeError: Cannot read properties of undefined (reading 'type')"},{"fix":"Run npm install babel-plugin-remove-object-properties --save-dev","cause":"Plugin not installed or not in node_modules.","error":"Error: [BABEL] unknown: Cannot find module 'babel-plugin-remove-object-properties'"},{"fix":"Use string form: \"regexp\": \"data-*\" (not /data-*/)","cause":"Passing regex literal instead of string in config.","error":"The regexp option must be a string"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}