rollup-plugin-delete

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

A Rollup plugin for deleting files and folders before or during a build, powered by the del package. Current stable version is 3.0.2, released as pure ESM requiring Node.js 18+. It is written in TypeScript and ships native types. Key differentiators include support for multiple target patterns, verbose output, customizable hook (e.g., buildStart, buildEnd), and a runOnce option for watch mode. Active maintenance with recent updates focused on modernizing internals (vitest to node test runner, tsdown).

error Error [ERR_REQUIRE_ESM]: require() of ES Module ... from ... not supported.
cause Importing the package with require() in a CommonJS environment, but v3+ is ESM-only.
fix
Use import del from 'rollup-plugin-delete' and ensure your project is ESM ("type": "module" in package.json), or downgrade to v2.x.
error TypeError: del is not a function
cause The default export is a factory function; importing the named export incorrectly or using a wrong import style.
fix
Use default import: import del from 'rollup-plugin-delete'
error Error: Cannot find module 'rollup-plugin-delete'
cause Package not installed or not listed in dependencies.
fix
Run npm install rollup-plugin-delete --save-dev (or yarn/pnpm equivalent).
breaking Package converted to pure ESM in v3.0.0 - require() will throw an error
fix Use import syntax instead of require(). If you must use CommonJS, stay on v2.x.
breaking Requires Node.js 18+ starting from v3.0.0
fix Upgrade Node.js to version 18 or later, or use v2.x for older Node versions.
breaking Underlying del package was upgraded with breaking changes in glob engine and options
fix Review del changelog for version 5.0.0 and adjust your glob patterns/options accordingly.
deprecated Support for Node.js 8 dropped in v2.0.0
fix Use Node.js 10+ or stay on v1.x.
gotcha Default hook is 'buildStart' - files are deleted at the start of the build, not the end
fix If you need deletion after bundle, set hook: 'buildEnd' or 'writeBundle'.
gotcha Using wildcard * in targets may cause confusion with dotfiles
fix Explicitly include dotfiles patterns (e.g., '**/.*') if you intend to delete hidden files.
npm install rollup-plugin-delete
yarn add rollup-plugin-delete
pnpm add rollup-plugin-delete

Shows basic usage: delete all files in 'dist' before bundle, with verbose output and runOnce to avoid re-deletion in watch mode.

// rollup.config.js
import del from 'rollup-plugin-delete';

export default {
  input: 'src/index.js',
  output: { file: 'dist/bundle.js' },
  plugins: [
    del({ targets: 'dist/*', verbose: true, runOnce: true })
  ]
};