{"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,"search_vec":"'2.0.0':25 'as-need':34 'basi':37 'build':44,67 'compon':63 'context':84 'depend':46,95 'develop':55 'differenti':69 'directori':52 'dynam':14 'enabl':53 'es':10 'esm':80,99 'extern':94 'focus':77 'fragment':43 'import':5,12,15,81,100 'isol':68 'javascript':96 'keep':66 'latest':28 'legaci':86 'maintain':31 'modul':11,51 'multi':89 'multi-repo':88 'need':36 'node':50 'owner':58 'path':16,23,73 'path-rewrit':72 'platform':57 'plugin':3,7,75,98,103 'prepend':18 'problem':41 'releas':30 'repo':90 'resid':47 'rewrit':4,9,74 'rollup':2,6,97,102 'rollup-plugin':101 'rollup-plugin-rewrite-import':1 'separ':49 'setup':91 'solv':39 'specif':78 'stabl':29 'standard':61 'string':20 'theme':54 'tool':64 'use':60 'version':24 'web':62","created_at":"2026-04-27T17:03:56.600775+00:00","updated_at":"2026-04-27T17:03:56.600775+00:00","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,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/elmsln/rollup-rewrite-imports","docs":null,"changelog":null,"pypi":null,"npm":"https://www.npmjs.com/package/rollup-plugin-rewrite-imports","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-18","next_check":"2026-07-26","install_tag":null}}