Registry / devops / rollup-plugin-rewrite-imports

rollup-plugin-rewrite-imports

JSON →
library2.0.0jsnpmunverified

Rollup plugin that rewrites ES module import and dynamic import paths by prepending a string to each path. Version 2.0.0 is the latest stable release; maintained on an as-needed basis. It solves the problem of fragmented builds where dependencies reside in separate node_modules directories, enabling theme developers and platform owners to use standard web component tooling while keeping builds isolated. Differentiates from other path-rewriting plugins by focusing specifically on ESM imports in the context of legacy or multi-repo setups, with no external dependencies.

npm install rollup-plugin-rewrite-imports
INSTALL
IMPORT
SIG · ROLLUP-PLUGIN-REWR
R
rollup-plugin-rewrite-imports
devopsjavascriptv2.0.0
Install
Import
Disk
Pass rate
0/ 6
Env Coverage0 / 6
glibc
1822
musl
1822
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 18223 runs
build_error
glibc
node 18223 runs
build_error
Code
Verified usage

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

rewriteImports
import rewriteImports from 'rollup-plugin-rewrite-imports'
const rewriteImports = require('rollup-plugin-rewrite-imports')
ESM-only since version 2.0.0; CommonJS require will not work.
rewriteImports
const rewriteImports = require('rollup-plugin-rewrite-imports').default
const rewriteImports = require('rollup-plugin-rewrite-imports')
If using CommonJS, you must access the .default property because the package is ESM-only.
rewriteImports
import rewriteImports from 'rollup-plugin-rewrite-imports'
import { rewriteImports } from 'rollup-plugin-rewrite-imports'
The module exports a single default function; named import will be undefined.

Configure Rollup to use rewriteImports, prepending a path to each import statement.

import rewriteImports from 'rollup-plugin-rewrite-imports'; import autoExternal from 'rollup-plugin-auto-external'; export default { input: 'src/custom.js', output: { file: 'build/custom.esm.js', format: 'esm', }, plugins: [ autoExternal(), rewriteImports('../../build/es6/node_modules/'), ], };
Debug
Known issues
breakingVersion 2.0.0 changed to ESM-only. CommonJS require() will fail without .default access.
fix
Use import syntax or require with .default, or downgrade to 1.x if CommonJS is required.
affects: >=2.0.0
deprecatedThe plugin does not support CJS; Node.js <12 or older bundlers may not handle ESM imports correctly.
fix
Ensure your runtime supports ESM or bundle with a tool that handles ESM-to-CJS conversion.
affects: >=2.0.0
gotchaThe plugin rewrites imports based on a simple string prefix; it does not understand module resolution. All imports (relative and bare) are prefixed indiscriminately.
fix
Use with care: ensure the prefix does not break valid import paths. Pair with rollup-plugin-auto-external or a resolve plugin to manage external dependencies.
affects: *
Errors
Common errors & fixes
require() of ES Module /path/to/rollup-plugin-rewrite-imports not supported.
Attempting to require() an ESM-only module with CommonJS require.
fix
Use dynamic import() or switch to import syntax, or add .default: const rewriteImports = require('rollup-plugin-rewrite-imports').default;
Cannot find module 'rollup-plugin-rewrite-imports'
Package not installed or not in node_modules.
fix
Run `npm install rollup-plugin-rewrite-imports --save-dev`.
import { rewriteImports } from 'rollup-plugin-rewrite-imports' returns undefined.
Named import used but the module exports a default export, not a named one.
fix
Use default import: import rewriteImports from 'rollup-plugin-rewrite-imports';
Upgrade
Version history
2.0.0latest on npm
Audit
Dependencies

No dependency data recorded yet.

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