rollup-plugin-rename-node-modules

raw JSON →
1.3.1 verified Mon Apr 27 auth: no javascript

A Rollup plugin that renames the `node_modules` directory in the output when bundling with `preserveModules` and also rewrites relative imports to point to the new folder. Version 1.3.1 is the latest stable release. It addresses a common npm publishing issue where npm ignores `node_modules` in the output directory. Supports a custom replacer function (since 1.3.0), optional source map generation (since 1.2.0), and requires Rollup 2.28.2+ and Node 8+. This is a niche utility for library authors bundling dependencies with `preserveModules`.

error Error: Cannot find module 'rollup-plugin-rename-node-modules'
cause The package is missing from node_modules; not installed.
fix
Run npm install rollup-plugin-rename-node-modules --save-dev
error TypeError: renameNodeModules is not a function
cause Using named import `{ renameNodeModules }` instead of default import.
fix
Use import renameNodeModules from 'rollup-plugin-rename-node-modules'
error Error: [plugin] rollup-plugin-rename-node-modules: Something went wrong
cause The plugin encountered an issue (e.g., invalid replacer or missing input).
fix
Verify that the first argument is a string or function; check Rollup config.
breaking The plugin renaming might not work correctly if the output directory is not flat?
fix Ensure the output structure matches expectations; test with nested modules.
deprecated The `sourceMap` option (second argument) has been available since 1.2.0; there is no deprecation, but note that it's an optional boolean.
fix Use the second argument to toggle source map generation. Passing `false` is valid.
gotcha When using a custom replacer function (since 1.3.0), it is applied to both file paths and import paths. Ensure it does not break relative paths.
fix Test the replacer with expected input strings.
breaking The plugin expects Rollup 2.28.2 or higher. Using it with older versions may cause errors.
fix Upgrade Rollup to >=2.28.2.
npm install rollup-plugin-rename-node-modules
yarn add rollup-plugin-rename-node-modules
pnpm add rollup-plugin-rename-node-modules

Basic Rollup config using the plugin with a custom folder name to avoid npm's node_modules ignore behavior.

import renameNodeModules from 'rollup-plugin-rename-node-modules';

export default {
  input: 'src/index.js',
  output: {
    dir: 'dist',
    format: 'cjs',
    preserveModules: true,
  },
  plugins: [renameNodeModules('external_modules')],
};