Registry / devops / rollup-plugin-replace-imports

rollup-plugin-replace-imports

JSON →
library1.0.0jsnpmunverified

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.

npm install rollup-plugin-replace-imports
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-REPL
R
rollup-plugin-replace-imports
devopsjavascriptv1.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
✓ import replaceImports from 'rollup-plugin-replace-imports'
✗ const replaceImports = require('rollup-plugin-replace-imports')
ESM-only; CommonJS require will fail in most bundlers due to lack of default export in CJS wrapper.
replaceImports
✓ import { replaceImports } from 'rollup-plugin-replace-imports'
✗ import replaceImports from 'rollup-plugin-replace-imports'
Named export exists but is equivalent; default import is preferred per docs.
Plugin
✓ import type { Plugin } from 'rollup'
✗ import { Plugin } from 'rollup-plugin-replace-imports'
The package does not export its own type; use Rollup's Plugin type for TypeScript.

Shows basic usage of replaceImports in a Rollup config to transform import paths from '/es/' to '/' for ESM output.

import replaceImports from 'rollup-plugin-replace-imports'; import resolve from '@rollup/plugin-node-resolve'; export default { input: 'src/index.js', output: { dir: 'dist', format: 'es', plugins: [ replaceImports(n => n.replace('/es/', '/')), ], }, plugins: [resolve()], };
Debug
Known issues
gotchaReplace function is called after bundle generation; modifications to paths that do not exist will not error.
fix
Ensure replacement string exists in at least one import path, or use a callback that logs unmatched paths for debugging.
affects: 1.0.0
breakingPlugin only works in output plugins array, not in top-level plugins array.
fix
Place replaceImports inside the output's plugins array, not the top-level plugins.
affects: 1.0.0
gotchaTypeScript definitions are not published with the package; users must supply their own types.
fix
Install @types/rollup-plugin-replace-imports separately (if available) or declare module manually.
affects: 1.0.0
Errors
Common errors & fixes
Error: Cannot find module 'rollup-plugin-replace-imports'
Package not installed or dependency missing.
fix
npm install rollup-plugin-replace-imports --save-dev
TypeError: replaceImports is not a function
Using CommonJS require instead of ESM import.
fix
Change to 'import replaceImports from 'rollup-plugin-replace-imports'' in an ESM context.
The plugin 'replaceImports' must be placed in the output plugins array.
Incorrectly placed in top-level plugins.
fix
Move replaceImports inside output.plugins array.
Upgrade
Version history
1.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
2 hits · last 30 days
node
2
Resources
rollup-plugin-replace-imports — npm install rollup-plugin-replace-imports · libregistry