rimraf
Cross-platform `rm -rf` for Node.js. Recursively deletes files and directories on Windows, macOS, and Linux. Handles Windows file locking issues that native rm -rf doesn't. Widely used in build scripts and package.json scripts for cleaning dist/ or build/ directories. v4+ uses native Node.js fs.rm() with rimraf as a reliable cross-platform wrapper.
Score Breakdown
⚙ Agent Friendliness
🔒 Security
Destructive operation — no confirmation. Path traversal bugs in calling code could delete unintended files. Always validate paths before passing to rimraf.
⚡ Reliability
Best When
Writing cross-platform npm scripts or Node.js build tools that need reliable recursive directory deletion.
Avoid When
Targeting modern Node.js 18+ on non-Windows systems — native fs.rm() is sufficient.
Use Cases
- • Clean build output directories (dist/, build/, .next/) in npm scripts cross-platform: "clean": "rimraf dist"
- • Delete temporary directories in Node.js build tools and scripts without platform-specific rm -rf / rmdir /s /q handling
- • Remove node_modules for clean reinstalls: rimraf node_modules && npm install
- • Use programmatic API in build scripts to delete files matching glob patterns cross-platform
- • Handle Windows file locking by retrying deletion with configurable backoff when files are in use
Not For
- • Production application code that deletes user data — rimraf is a build tool; use explicit fs operations with validation for production file deletion
- • Cases where Node.js 14.14+ native fs.rm({recursive: true, force: true}) suffices — rimraf adds value primarily on older Node.js or Windows
- • Fast batch file operations — rimraf has overhead vs native C implementations for large directory trees
Interface
Authentication
Build tool — no auth needed.
Pricing
ISC licensed open source library.
Agent Metadata
Known Gotchas
- ⚠ rimraf v4/v5 is ESM-first — require('rimraf') may fail in CommonJS projects; use import or the sync export explicitly
- ⚠ rimraf v3 to v4 migration: the default export changed from synchronous to async — wrap in await or use rimrafSync for sync behavior
- ⚠ Glob patterns in rimraf v4+ use glob package patterns — paths with special characters must be escaped
- ⚠ rimraf does not throw for non-existent paths by default — check if deletion actually occurred if your code depends on path existence
- ⚠ Windows: rimraf retries on EBUSY errors with backoff — deletion may take longer than expected when files are open in other processes
- ⚠ rimraf deletes WITHOUT confirmation or recycle bin — there is no undo; always verify the path before calling rimraf in scripts
Alternatives
Full Evaluation Report
Detailed scoring breakdown, competitive positioning, security analysis, and improvement recommendations for rimraf.
Scores are editorial opinions as of 2026-03-06.