{"id":22204,"library":"rollup-plugin-rewrite-imports","title":"rollup-plugin-rewrite-imports","description":"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.","status":"maintenance","version":"2.0.0","language":"javascript","source_language":"en","source_url":"https://github.com/elmsln/rollup-rewrite-imports","tags":["javascript","rollup","plugin","esm","imports","rollup-plugin"],"install":[{"cmd":"npm install rollup-plugin-rewrite-imports","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-rewrite-imports","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-rewrite-imports","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"ESM-only since version 2.0.0; CommonJS require will not work.","wrong":"const rewriteImports = require('rollup-plugin-rewrite-imports')","symbol":"rewriteImports","correct":"import rewriteImports from 'rollup-plugin-rewrite-imports'"},{"note":"If using CommonJS, you must access the .default property because the package is ESM-only.","wrong":"const rewriteImports = require('rollup-plugin-rewrite-imports')","symbol":"rewriteImports","correct":"const rewriteImports = require('rollup-plugin-rewrite-imports').default"},{"note":"The module exports a single default function; named import will be undefined.","wrong":"import { rewriteImports } from 'rollup-plugin-rewrite-imports'","symbol":"rewriteImports","correct":"import rewriteImports from 'rollup-plugin-rewrite-imports'"}],"quickstart":{"code":"import rewriteImports from 'rollup-plugin-rewrite-imports';\nimport autoExternal from 'rollup-plugin-auto-external';\n\nexport default {\n  input: 'src/custom.js',\n  output: {\n    file: 'build/custom.esm.js',\n    format: 'esm',\n  },\n  plugins: [\n    autoExternal(),\n    rewriteImports('../../build/es6/node_modules/'),\n  ],\n};","lang":"javascript","description":"Configure Rollup to use rewriteImports, prepending a path to each import statement."},"warnings":[{"fix":"Use import syntax or require with .default, or downgrade to 1.x if CommonJS is required.","message":"Version 2.0.0 changed to ESM-only. CommonJS require() will fail without .default access.","severity":"breaking","affected_versions":">=2.0.0"},{"fix":"Ensure your runtime supports ESM or bundle with a tool that handles ESM-to-CJS conversion.","message":"The plugin does not support CJS; Node.js <12 or older bundlers may not handle ESM imports correctly.","severity":"deprecated","affected_versions":">=2.0.0"},{"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.","message":"The plugin rewrites imports based on a simple string prefix; it does not understand module resolution. All imports (relative and bare) are prefixed indiscriminately.","severity":"gotcha","affected_versions":"*"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Use dynamic import() or switch to import syntax, or add .default: const rewriteImports = require('rollup-plugin-rewrite-imports').default;","cause":"Attempting to require() an ESM-only module with CommonJS require.","error":"require() of ES Module /path/to/rollup-plugin-rewrite-imports not supported."},{"fix":"Run `npm install rollup-plugin-rewrite-imports --save-dev`.","cause":"Package not installed or not in node_modules.","error":"Cannot find module 'rollup-plugin-rewrite-imports'"},{"fix":"Use default import: import rewriteImports from 'rollup-plugin-rewrite-imports';","cause":"Named import used but the module exports a default export, not a named one.","error":"import { rewriteImports } from 'rollup-plugin-rewrite-imports' returns undefined."}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}