{"id":22133,"library":"rollup-plugin-modify","title":"rollup-plugin-modify","description":"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.","status":"active","version":"3.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/porsager/rollup-plugin-modify","tags":["javascript","rollup-plugin","replace","find","regex","regexp","modify","codemod","magic-string"],"install":[{"cmd":"npm install rollup-plugin-modify","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-modify","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-modify","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"used to perform source map-aware string manipulation on bundle output","package":"magic-string","optional":false},{"reason":"peer dependency required for plugin context","package":"rollup","optional":false}],"imports":[{"note":"Package is ESM-only since v3. CommonJS require() will fail.","wrong":"const modify = require('rollup-plugin-modify')","symbol":"default (modify)","correct":"import modify from 'rollup-plugin-modify'"},{"note":"There is no named export; only a default export.","wrong":"import { modify } from 'rollup-plugin-modify'","symbol":"Named export (none)","correct":"import modify from 'rollup-plugin-modify'"},{"note":"TypeScript should use ESM import syntax. Types are included in the package.","wrong":"import modify = require('rollup-plugin-modify')","symbol":"TypeScript types","correct":"import modify from 'rollup-plugin-modify'"}],"quickstart":{"code":"// rollup.config.js\nimport modify from 'rollup-plugin-modify'\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'es'\n  },\n  plugins: [\n    modify({\n      find: /process\\.env\\.([\\w_]+)/g,\n      replace: (match, key) => process.env[key] ?? ''\n    })\n  ]\n}","lang":"javascript","description":"Replaces process.env.* variables with actual environment variables in the output bundle, using a dynamic replace function."},"warnings":[{"fix":"Update Node.js to >=12 and use ESM imports. For CJS projects, use dynamic import() or stick to v2.","message":"rollup-plugin-modify v3 is ESM-only and requires Node.js >= 12. Modules must be loaded via import.","severity":"breaking","affected_versions":">=3.0"},{"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.","message":"The 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.","severity":"breaking","affected_versions":">=3.0"},{"fix":"Use the explicit syntax for RegExp: modify({ find: /pattern/, replace: 'replacement' })","message":"When 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.","severity":"gotcha","affected_versions":">=3.0"},{"fix":"Use (match, ...args) => { ... } and extract groups as needed.","message":"The 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.","severity":"gotcha","affected_versions":">=3.0"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use dynamic import: const modify = (await import('rollup-plugin-modify')).default;","cause":"rollup-plugin-modify v3+ is ESM-only, so require() fails.","error":"Error [ERR_REQUIRE_ESM]: require() of ES Module not supported"},{"fix":"Use import modify from 'rollup-plugin-modify' (no braces).","cause":"Using named import { modify } instead of default import.","error":"TypeError: modify is not a function"},{"fix":"Ensure find is either a string or RegExp. For multiple patterns, use the terse object syntax or multiple plugins.","cause":"Passed non-string/non-RegExp as find (e.g., array or number).","error":"The 'find' argument must be of type string or an instance of RegExp"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}