rollup-plugin-rm
raw JSON → 1.0.2 verified Mon Apr 27 auth: no javascript
A Rollup plugin that executes the rm (remove) command during build hooks, specifically buildStart or buildEnd. Version 1.0.2 (current stable) has a low release cadence. It is a minimal alternative to rollup-plugin-delete or rollup-plugin-clean, offering no-config deletion via a simple string path argument. It ships TypeScript types and requires Rollup 3 or 4 as a peer dependency. Unlike alternatives, it does not support glob patterns or multiple directories—only a single path removal.
Common errors
error TypeError: rollup_plugin_rm_default is not a function ↓
cause Using named import 'rm' instead of default import
fix
Use
import rm from 'rollup-plugin-rm' error Error [ERR_REQUIRE_ESM]: require() of ES Module ↓
cause Using require() in a CommonJS context for an ESM-only package
fix
Migrate to ESM ('type':'module' in package.json) or use dynamic import:
const rm = (await import('rollup-plugin-rm')).default error Error: Cannot find module 'rollup' (or peer dependency missing) ↓
cause Rollup not installed as a dependency
fix
Run
npm install rollup --save-dev error rollup-plugin-rm: Path must be a string ↓
cause Passing an array or undefined as the path argument
fix
Pass a single string path:
rm('dist', 'buildStart'). Use multiple calls for multiple paths. Warnings
breaking Only supports string path argument, not an array of paths or glob patterns. Multiple directories require multiple plugin calls. ↓
fix Use multiple rm() calls for each directory, or switch to rollup-plugin-delete for glob support.
gotcha Plugin uses synchronous rimraf under the hood. It may block the build for large directories; consider using asynchronous alternatives if performance is critical. ↓
fix For large directories, remove synchronously via buildStart/buildEnd hooks manually using fs.promises.rm.
deprecated No deprecation warnings yet. Keep an eye on future releases for possible switch to async deletion. ↓
fix Monitor GitHub releases for potential breaking changes.
gotcha If the path does not exist, rimraf fails silently? Ensure the directory exists or wrap in try/catch? Documentation does not specify behavior for non-existent paths. ↓
fix Check existence before calling rm plugin; the underlying rimraf version may throw on ENOENT.
breaking Rollup 3 or 4 is required as peer dependency. Older Rollup 2 is not supported and will cause runtime hook mismatches. ↓
fix Upgrade Rollup to version 3 or 4, or use rollup-plugin-delete which supports Rollup 2.
Install
npm install rollup-plugin-rm yarn add rollup-plugin-rm pnpm add rollup-plugin-rm Imports
- default wrong
const rm = require('rollup-plugin-rm')correctimport rm from 'rollup-plugin-rm' - rm wrong
import { rm } from 'rollup-plugin-rm'correctimport rm from 'rollup-plugin-rm' - RollupPluginRmOptions wrong
import { RollupPluginRmOptions } from 'rollup-plugin-rm'correctimport type { RollupPluginRmOptions } from 'rollup-plugin-rm'
Quickstart
import rm from 'rollup-plugin-rm';
import { defineConfig } from 'rollup';
export default defineConfig({
input: 'src/index.js',
output: { dir: 'output', format: 'cjs' },
plugins: [
rm('dist', 'buildStart'),
rm('dist/types', 'buildEnd')
]
});