{"id":22102,"library":"rollup-plugin-jsx-remove-attributes","title":"rollup-plugin-jsx-remove-attributes","description":"A Rollup and Vite plugin to remove specified JSX attributes (e.g., data-testid) from production builds, reducing bundle size. Current version 3.1.2, requires Node >=20.8.0. Supports Rollup and Vite, with Preact support added in v3.1.0. Key differentiator: simple configuration for stripping test-only attributes without Babel plugin overhead. Active development, peer deps include @rollup/pluginutils, astring, estree-walker, and Vite >=5.2. Ships TypeScript types.","status":"active","version":"3.1.2","language":"javascript","source_language":"en","source_url":"https://github.com/jacobbogers/rollup-plugin-jsx-remove-attributes","tags":["javascript","vite-plugin","rollup-plugin","data-testid","remove attribute","typescript"],"install":[{"cmd":"npm install rollup-plugin-jsx-remove-attributes","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-jsx-remove-attributes","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-jsx-remove-attributes","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Filtering files by include/exclude patterns","package":"@rollup/pluginutils","optional":false},{"reason":"AST node manipulation to remove attributes","package":"astring","optional":false},{"reason":"Walking the ESTree AST","package":"estree-walker","optional":false},{"reason":"Required when usage is 'vite'","package":"vite","optional":true}],"imports":[{"note":"Default export; named import will fail. ESM-only (no CJS).","wrong":"import { removeTestIdAttribute } from 'rollup-plugin-jsx-remove-attributes'","symbol":"removeTestIdAttribute","correct":"import removeTestIdAttribute from 'rollup-plugin-jsx-remove-attributes'"},{"note":"In CJS, use default require; destructuring will give undefined.","wrong":"const { removeTestIdAttribute } = require('rollup-plugin-jsx-remove-attributes')","symbol":"removeTestIdAttribute","correct":"const removeTestIdAttribute = require('rollup-plugin-jsx-remove-attributes')"},{"note":"Type import for TypeScript users.","wrong":"","symbol":"PluginOptions","correct":"import type { PluginOptions } from 'rollup-plugin-jsx-remove-attributes'"}],"quickstart":{"code":"import { defineConfig } from 'vite';\nimport react from '@vitejs/plugin-react';\nimport removeTestIdAttribute from 'rollup-plugin-jsx-remove-attributes';\n\nexport default defineConfig({\n  plugins: [\n    react(),\n    removeTestIdAttribute({\n      include: [/\\.tsx$/],\n      exclude: ['node_modules/**'],\n      attributes: ['data-testid', 'data-cy'],\n      environments: ['production', 'staging'],\n      usage: 'vite'\n    })\n  ]\n});","lang":"typescript","description":"Configures Vite to remove 'data-testid' and 'data-cy' attributes from JSX in production builds."},"warnings":[{"fix":"Upgrade Node to v20.8.0 or later.","message":"Requires Node >=v20.8.0; older Node versions will fail to install or run.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Migrate to v3 API.","message":"Version 2.x used a different API (options object keys). v3 changed to attributes array and environments option.","severity":"deprecated","affected_versions":">=3.0.0"},{"fix":"Set NODE_ENV or use 'environments' option to include 'development' if needed.","message":"The plugin only runs when NODE_ENV matches an environment in the environments array (default ['production']). No attributes removed in dev.","severity":"gotcha","affected_versions":">=1.0.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Change to: import removeTestIdAttribute from 'rollup-plugin-jsx-remove-attributes'","cause":"Using named import instead of default import","error":"TypeError: removeTestIdAttribute is not a function"},{"fix":"Ensure NODE_ENV=production or adjust environments option.","cause":"NODE_ENV not set or not in environments array","error":"Error: The plugin only works when NODE_ENV is set to 'production' or specified environments."},{"fix":"Run npm install again and verify peer dependencies.","cause":"Missing or incomplete installation","error":"ENOENT: no such file or directory, open '.../node_modules/rollup-plugin-jsx-remove-attributes/package.json'"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}