Skip to content
Latchkey

Node.js "rimraf: command not found" in CI

A clean script calls rimraf to delete build output, but the binary is missing in CI. As a devDependency, it disappears under a production install and the script exits 127.

What this error means

A clean or prebuild script using rimraf dist fails with rimraf: command not found. The same script works locally where dev deps are installed.

node
> clean
> rimraf dist

sh: rimraf: command not found
npm ERR! code 127

Common causes

rimraf is a missing devDependency

rimraf is dev-only. With dev deps pruned or uninstalled, the binary is absent and the clean step fails.

How to fix it

Install rimraf or use it via npx

Add rimraf to devDependencies, or invoke it through npx so it resolves from the registry if absent.

Terminal
npm install -D rimraf
# or call without a local install
npx rimraf dist

Use a built-in delete instead

Recent Node has a portable recursive remove, removing the dependency for simple cleans.

package.json
node --eval "fs.rmSync('dist', { recursive: true, force: true })"

How to prevent it

  • Keep dev deps installed for build/clean jobs.
  • Prefer the built-in recursive remove for simple cleans.
  • Declare every CLI used by scripts in package.json.

Related guides

Tired of flaky CI? Latchkey auto-heals failed jobs and retries them for you. Start free →