Registry /
devops / rollup-plugin-path-rewrite
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
muslnode 18–223 runs
build_error
glibcnode 18–223 runs
build_error
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
pathRewrite
✓ import pathRewrite from 'rollup-plugin-path-rewrite'
✗ import { pathRewrite } from 'rollup-plugin-path-rewrite'
Default export only; named import will cause undefined.
(none)
✓ const pathRewrite = require('rollup-plugin-path-rewrite')
✗ const { pathRewrite } = require('rollup-plugin-path-rewrite')
CJS usage: the entire module exports the plugin function as default.
RollupPluginPathRewriteOptions
✓ import type { RollupPluginPathRewriteOptions } from 'rollup-plugin-path-rewrite'
TypeScript: type is exported for option configuration.
Minimal rollup config using pathRewrite to move .d.ts files into a types/ subdirectory while preserving modules.
// rollup.config.js
import pathRewrite from 'rollup-plugin-path-rewrite';
export default {
input: 'src/index.js',
output: {
dir: 'dist',
format: 'es',
preserveModules: true,
},
plugins: [
pathRewrite({
test: /\.d\.ts$/i,
replaceTo: (path) => `types/${path}`,
}),
],
};
Debug
Known issues
breakingPlugin only operates on generated output paths; it does not modify file contents. If you need content transformation, use a different plugin.fixEnsure your use case is purely path rewriting; for content changes, use rollup-plugin-replace or similar.
affects: >=1.0.0
gotchaThe `replaceTo` option can be a string or function. If a string, it does NOT support regex replacement groups like $1. Use a function for regex group replacements.fixFor group replacements: `replaceTo: (path) => path.replace(/pattern/, '$1')`
affects: >=1.0.0
gotchaThe plugin relies on Rollup's output options like `preserveModules` to generate separate files. Without `preserveModules`, there may be fewer paths to rewrite.fixIf paths are not being rewritten, verify that `preserveModules: true` is set in the output config.
affects: >=1.0.0
deprecatedNo known deprecations.
Errors
Common errors & fixes
TypeError: pathRewrite is not a function
Using named import instead of default import.
fixChange `import { pathRewrite }` to `import pathRewrite` Error: Could not resolve 'rollup-plugin-path-rewrite' (missing peer dep rollup)
Rollup is not installed as a dev dependency or peer dependency.
fixRun `npm install rollup --save-dev`
InputError: The plugin does not modify files in place; no output directories matched your filter.
The `test` regex does not match any generated output paths, or `preserveModules` is not enabled.
fixEnsure `preserveModules: true` is set and the `test` regex matches the file extensions you expect.
Audit
Dependencies
rolluprequiredPeer dependency: required as the plugin host.