{"id":22197,"library":"rollup-plugin-rename-node-modules","title":"rollup-plugin-rename-node-modules","description":"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`.","status":"active","version":"1.3.1","language":"javascript","source_language":"en","source_url":"https://github.com/Lazyuki/rollup-plugin-rename-node-modules","tags":["javascript","rollup","plugin","rollup-plugin","node_modules","rename","typescript"],"install":[{"cmd":"npm install rollup-plugin-rename-node-modules","lang":"bash","label":"npm"},{"cmd":"yarn add rollup-plugin-rename-node-modules","lang":"bash","label":"yarn"},{"cmd":"pnpm add rollup-plugin-rename-node-modules","lang":"bash","label":"pnpm"}],"dependencies":[{"reason":"Peer dependency; the plugin is designed to work as a Rollup plugin and requires Rollup 2.28.2+.","package":"rollup","optional":false}],"imports":[{"note":"The plugin is ESM-only and ships TypeScript definitions. CommonJS require is not supported.","wrong":"const renameNodeModules = require('rollup-plugin-rename-node-modules')","symbol":"default (renameNodeModules)","correct":"import renameNodeModules from 'rollup-plugin-rename-node-modules'"},{"note":"Call as a function with a string or replacer function. The second argument is optional (sourceMap) and defaults to true. Forgetting to call it (e.g., using the import itself) will silently fail.","wrong":"plugins: [renameNodeModules('ext')]","symbol":"renameNodeModules","correct":"plugins: [renameNodeModules('ext', false)]"},{"note":"The package exports a default function named renameNodeModules, not a named export. Using named import will result in undefined.","wrong":"import { renameNodeModules } from 'rollup-plugin-rename-node-modules'","symbol":"TypeScript usage","correct":"import renameNodeModules from 'rollup-plugin-rename-node-modules'"}],"quickstart":{"code":"import renameNodeModules from 'rollup-plugin-rename-node-modules';\n\nexport default {\n  input: 'src/index.js',\n  output: {\n    dir: 'dist',\n    format: 'cjs',\n    preserveModules: true,\n  },\n  plugins: [renameNodeModules('external_modules')],\n};","lang":"typescript","description":"Basic Rollup config using the plugin with a custom folder name to avoid npm's node_modules ignore behavior."},"warnings":[{"fix":"Ensure the output structure matches expectations; test with nested modules.","message":"The plugin renaming might not work correctly if the output directory is not flat?","severity":"breaking","affected_versions":"<=1.3.1"},{"fix":"Use the second argument to toggle source map generation. Passing `false` is valid.","message":"The `sourceMap` option (second argument) has been available since 1.2.0; there is no deprecation, but note that it's an optional boolean.","severity":"deprecated","affected_versions":">=1.2.0"},{"fix":"Test the replacer with expected input strings.","message":"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.","severity":"gotcha","affected_versions":">=1.3.0"},{"fix":"Upgrade Rollup to >=2.28.2.","message":"The plugin expects Rollup 2.28.2 or higher. Using it with older versions may cause errors.","severity":"breaking","affected_versions":"<2.28.2"}],"env_vars":null,"last_verified":"2026-04-27T00:00:00.000Z","next_check":"2026-07-26T00:00:00.000Z","problems":[{"fix":"Run `npm install rollup-plugin-rename-node-modules --save-dev`","cause":"The package is missing from node_modules; not installed.","error":"Error: Cannot find module 'rollup-plugin-rename-node-modules'"},{"fix":"Use `import renameNodeModules from 'rollup-plugin-rename-node-modules'`","cause":"Using named import `{ renameNodeModules }` instead of default import.","error":"TypeError: renameNodeModules is not a function"},{"fix":"Verify that the first argument is a string or function; check Rollup config.","cause":"The plugin encountered an issue (e.g., invalid replacer or missing input).","error":"Error: [plugin] rollup-plugin-rename-node-modules: Something went wrong"}],"ecosystem":"npm","meta_description":null,"install_score":null,"install_tag":null,"quickstart_score":null,"quickstart_tag":null}