{"id":22199,"library":"rollup-plugin-replace-imports","title":"rollup-plugin-replace-imports","description":"A Rollup plugin that replaces import paths in bundled output, useful for creating dual CJS/ESM builds by transforming module specifiers (e.g., replacing '/es/' with '/'). Version 1.0.0 is stable but sparsely documented; no known release cadence or major updates. Unlike more complex plugin chains, this focuses on a single transformation function applied after module resolution.","status":"active","version":"1.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/fengxinming/rollup-plugins/tree/master/packages/rollup-plugin-replace-imports","tags":["javascript","rollup","rollup-plugin-replace-imports","rollup-plugin"],"install":[{"cmd":"npm install rollup-plugin-replace-imports","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-replace-imports","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-replace-imports","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only; CommonJS require will fail in most bundlers due to lack of default export in CJS wrapper.","wrong":"const replaceImports = require('rollup-plugin-replace-imports')","symbol":"default","correct":"import replaceImports from 'rollup-plugin-replace-imports'"},{"note":"Named export exists but is equivalent; default import is preferred per docs.","wrong":"import replaceImports from 'rollup-plugin-replace-imports'","symbol":"replaceImports","correct":"import { replaceImports } from 'rollup-plugin-replace-imports'"},{"note":"The package does not export its own type; use Rollup's Plugin type for TypeScript.","wrong":"import { Plugin } from 'rollup-plugin-replace-imports'","symbol":"Plugin","correct":"import type { Plugin } from 'rollup'"}],"quickstart":{"code":"import replaceImports from 'rollup-plugin-replace-imports';\nimport resolve from '@rollup/plugin-node-resolve';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'es',\n    plugins: [\n      replaceImports(n => n.replace('/es/', '/')),\n    ],\n  },\n  plugins: [resolve()],\n};","lang":"javascript","description":"Shows basic usage of replaceImports in a Rollup config to transform import paths from '/es/' to '/' for ESM output."},"warnings":[{"fix":"Ensure replacement string exists in at least one import path, or use a callback that logs unmatched paths for debugging.","message":"Replace function is called after bundle generation; modifications to paths that do not exist will not error.","severity":"gotcha","affected_versions":"1.0.0"},{"fix":"Place replaceImports inside the output's plugins array, not the top-level plugins.","message":"Plugin only works in output plugins array, not in top-level plugins array.","severity":"breaking","affected_versions":"1.0.0"},{"fix":"Install @types/rollup-plugin-replace-imports separately (if available) or declare module manually.","message":"TypeScript definitions are not published with the package; users must supply their own types.","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":"npm install rollup-plugin-replace-imports --save-dev","cause":"Package not installed or dependency missing.","error":"Error: Cannot find module 'rollup-plugin-replace-imports'"},{"fix":"Change to 'import replaceImports from 'rollup-plugin-replace-imports'' in an ESM context.","cause":"Using CommonJS require instead of ESM import.","error":"TypeError: replaceImports is not a function"},{"fix":"Move replaceImports inside output.plugins array.","cause":"Incorrectly placed in top-level plugins.","error":"The plugin 'replaceImports' must be placed in the output plugins array."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}