Registry / devops / rollup-plugin-jsx-remove-attributes

rollup-plugin-jsx-remove-attributes

JSON →
library3.1.2jsnpmunverified

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.

npm install rollup-plugin-jsx-remove-attributes
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-JSX-
R
rollup-plugin-jsx-remove-attributes
devopsjavascriptv3.1.2
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
Install & Compatibility
Where this runs
tested against v? · npm install
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
node 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

removeTestIdAttribute
import removeTestIdAttribute from 'rollup-plugin-jsx-remove-attributes'
import { removeTestIdAttribute } from 'rollup-plugin-jsx-remove-attributes'
Default export; named import will fail. ESM-only (no CJS).
removeTestIdAttribute
const removeTestIdAttribute = require('rollup-plugin-jsx-remove-attributes')
const { removeTestIdAttribute } = require('rollup-plugin-jsx-remove-attributes')
In CJS, use default require; destructuring will give undefined.
PluginOptions
import type { PluginOptions } from 'rollup-plugin-jsx-remove-attributes'
Type import for TypeScript users.

Configures Vite to remove 'data-testid' and 'data-cy' attributes from JSX in production builds.

import { defineConfig } from 'vite'; import react from '@vitejs/plugin-react'; import removeTestIdAttribute from 'rollup-plugin-jsx-remove-attributes'; export default defineConfig({ plugins: [ react(), removeTestIdAttribute({ include: [/\.tsx$/], exclude: ['node_modules/**'], attributes: ['data-testid', 'data-cy'], environments: ['production', 'staging'], usage: 'vite' }) ] });
Debug
Known issues
breakingRequires Node >=v20.8.0; older Node versions will fail to install or run.
fix
Upgrade Node to v20.8.0 or later.
affects: >=3.0.0
deprecatedVersion 2.x used a different API (options object keys). v3 changed to attributes array and environments option.
fix
Migrate to v3 API.
affects: >=3.0.0
gotchaThe plugin only runs when NODE_ENV matches an environment in the environments array (default ['production']). No attributes removed in dev.
fix
Set NODE_ENV or use 'environments' option to include 'development' if needed.
affects: >=1.0.0
Errors
Common errors & fixes
TypeError: removeTestIdAttribute is not a function
Using named import instead of default import
fix
Change to: import removeTestIdAttribute from 'rollup-plugin-jsx-remove-attributes'
Error: The plugin only works when NODE_ENV is set to 'production' or specified environments.
NODE_ENV not set or not in environments array
fix
Ensure NODE_ENV=production or adjust environments option.
ENOENT: no such file or directory, open '.../node_modules/rollup-plugin-jsx-remove-attributes/package.json'
Missing or incomplete installation
fix
Run npm install again and verify peer dependencies.
Upgrade
Version history
3.1.2latest on npm
Audit
Dependencies
@rollup/pluginutilsrequiredFiltering files by include/exclude patterns
astringrequiredAST node manipulation to remove attributes
estree-walkerrequiredWalking the ESTree AST
viteoptionalRequired when usage is 'vite'
Agent activity
2 hits · last 30 days
node
2
Resources
rollup-plugin-jsx-remove-attributes — npm install rollup-plugin-jsx-remove-attributes · libregistry