rollup-plugin-node-copy

raw JSON →
1.0.4 verified Mon Apr 27 auth: no javascript maintenance

Rollup plugin (v1.0.4, last updated 2022) that brute-force copies Node.js modules and their dependencies into a target node_modules directory when Rollup cannot bundle them. Unlike typical resolve plugins that bundle imports, this plugin works around issues with native addons or impure modules by physically copying files to a destination folder (e.g., public/web/node_modules). Supports symlinking for development. Minimal configuration: pass an array of package names. No frequent releases; likely stable but unmaintained.

error Error: Cannot find module 'jimp' when using rollup-plugin-node-copy
cause The plugin copies the package but Rollup still tries to resolve it and fails if not properly handled.
fix
After copying, mark the package as external: external: ['jimp'] in Rollup config.
error TypeError: nodeCopy is not a function
cause Incorrect import style (named import instead of default).
fix
Use import nodeCopy from 'rollup-plugin-node-copy' or const nodeCopy = require('rollup-plugin-node-copy').
gotcha The plugin copies entire packages and their dependencies, which can bloat the output. Use only for modules that truly cannot be bundled.
fix Verify that the target module is not resolvable by other plugins before resorting to copying.
gotcha symlink: true creates symlinks to the source node_modules, which may cause issues with relative paths or absolute paths in production deployments.
fix Use symlink: false for production builds.
gotcha The src path must contain a top-level node_modules folder. If src is './', the plugin looks for './node_modules/'.
fix Ensure the source directory has a node_modules folder at the expected location.
npm install rollup-plugin-node-copy
yarn add rollup-plugin-node-copy
pnpm add rollup-plugin-node-copy

Demonstrates copying the jimp package and its dependencies to public/web/node_modules when Rollup cannot bundle it.

import nodeCopy from 'rollup-plugin-node-copy';

export default {
  input: 'src/index.js',
  output: { dir: 'dist', format: 'cjs' },
  plugins: [
    nodeCopy({
      packages: ['jimp'],
      src: './',
      dest: 'public/web',
      symlink: false
    })
  ]
};