Registry / devops / rollup-plugin-modify

rollup-plugin-modify

JSON →
library3.0.0jsnpmunverified

Rollup plugin for find-and-replace transformations on output bundles. Version 3.0.0 is current and stable, with no major release cadence. Supports both string/regex find with string/function replace, and a terse object syntax for multiple replacements. Uses magic-string under the hood for source map preservation. Unlike @rollup/plugin-replace, this plugin operates on the entire output file content rather than on AST nodes, making it suitable for regex-based codemods.

npm install rollup-plugin-modify
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-MODI
R
rollup-plugin-modify
devopsjavascriptv3.0.0
Install
—
Import
—
Disk
—
Pass rate
0/ 6
Env Coverage0 / 6
glibc
18–22
musl
18–22
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 18–223 runs
build_error
glibc
node 18–223 runs
build_error
Code
Verified usage

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

default (modify)
✓ import modify from 'rollup-plugin-modify'
✗ const modify = require('rollup-plugin-modify')
Package is ESM-only since v3. CommonJS require() will fail.
Named export (none)
✓ import modify from 'rollup-plugin-modify'
✗ import { modify } from 'rollup-plugin-modify'
There is no named export; only a default export.
TypeScript types
✓ import modify from 'rollup-plugin-modify'
✗ import modify = require('rollup-plugin-modify')
TypeScript should use ESM import syntax. Types are included in the package.

Replaces process.env.* variables with actual environment variables in the output bundle, using a dynamic replace function.

// rollup.config.js import modify from 'rollup-plugin-modify' export default { input: 'src/index.js', output: { dir: 'dist', format: 'es' }, plugins: [ modify({ find: /process\.env\.([\w_]+)/g, replace: (match, key) => process.env[key] ?? '' }) ] }
Debug
Known issues
breakingrollup-plugin-modify v3 is ESM-only and requires Node.js >= 12. Modules must be loaded via import.
fix
Update Node.js to >=12 and use ESM imports. For CJS projects, use dynamic import() or stick to v2.
affects: >=3.0
breakingThe options format changed from v1/v2. The legacy 'options' object with separate 'find' and 'replace' is still supported, but the terse key-value object syntax is now the primary use.
fix
If you were using a single options object with 'find' and 'replace' keys, that still works. No migration needed unless you used undocumented API.
affects: >=3.0
gotchaWhen using the terse object syntax, all keys are treated as strings (find patterns). To use a RegExp, you must use the explicit { find, replace } syntax.
fix
Use the explicit syntax for RegExp: modify({ find: /pattern/, replace: 'replacement' })
affects: >=3.0
gotchaThe replace function receives the entire match array from String.prototype.replace, not just the first argument. Ensure your function signature matches the expected (match, ...groups) pattern.
fix
Use (match, ...args) => { ... } and extract groups as needed.
affects: >=3.0
Errors
Common errors & fixes
Error [ERR_REQUIRE_ESM]: require() of ES Module not supported
rollup-plugin-modify v3+ is ESM-only, so require() fails.
fix
Use dynamic import: const modify = (await import('rollup-plugin-modify')).default;
TypeError: modify is not a function
Using named import { modify } instead of default import.
fix
Use import modify from 'rollup-plugin-modify' (no braces).
The 'find' argument must be of type string or an instance of RegExp
Passed non-string/non-RegExp as find (e.g., array or number).
fix
Ensure find is either a string or RegExp. For multiple patterns, use the terse object syntax or multiple plugins.
Upgrade
Version history
3.0.0latest on npm
Audit
Dependencies
magic-stringrequiredused to perform source map-aware string manipulation on bundle output
rolluprequiredpeer dependency required for plugin context
Agent activity
4 hits · last 30 days
node
4
Resources
rollup-plugin-modify — npm install rollup-plugin-modify · libregistry