cleaninstall-node v3.0.0
CLI for npm · pnpm · yarn · bun

Stop deleting node_modules. Find out why it broke.

cleaninstall-node diagnoses broken installs and applies the smallest fix that works, warns you the moment a git pull changes your dependencies, and cleans safely across monorepos when you really do want a fresh start.

$npx cleaninstall-node doctor
Install Source
Works withnpmpnpmyarnbunworkspaceshusky
$ npx cleaninstall-node doctor

🩺 cleaninstall-node doctor — ~/code/app (npm)

  ✖ node_modules is out of sync with package-lock.json (1 difference)
      ms: installed 2.1.3, lockfile 2.1.2
      Usually happens after git pull / switching branches without reinstalling.
  ✖ 1 native module was built for a different Node version
      better-sqlite3: built for ABI 115, this Node needs 127
  ✔ Node v22.11.0 matches .nvmrc (22)
  ✔ All 42 direct dependencies installed and in range

2 errors, 0 warnings.

Smallest fix (run with --fix to apply):
  → npm install
  → npm rebuild better-sqlite3
Three tools, one install

The fix is rarely “delete everything”

Most broken installs have one specific cause. cleaninstall-node finds it, tells you, and fixes only that, so you can skip the five-minute reinstall.

doctor

Checks your Node version, lockfile sync, dependency ranges, native modules and package manager, then suggests the smallest fix. --fix applies it.

git hook

After a pull, branch switch or rebase changes your dependencies, it warns you (or runs the install) before you hit a confusing error.

clean

Workspace-aware removal of node_modules, build output and caches. It shows sizes, asks once, and keeps your lockfiles unless you say otherwise.

doctor

Diagnose first. Fix the smallest thing.

doctor looks at what's actually installed, compares it with what your project asks for, and suggests the least disruptive repair.

01 · TRIED FIRST

Rebuild one package

npm rebuild better-sqlite3

A native module was built for another Node version or for another OS/CPU (a Docker volume, Rosetta).

02

Install

npm install

node_modules doesn't match the lockfile, or a dependency is missing or out of range.

03 · LAST RESORT

Clean reinstall

rm node_modules + install

Only when node_modules was written by a different package manager than the project uses.

On the wrong Node version, --fix does nothing and tells you to switch first, so nothing gets rebuilt for the wrong Node.

CheckCatchesFix
Node versionRunning Node vs .nvmrc, .node-version, .tool-versions, Volta, engines.nodenvm use
Lockfile syncnode_modules doesn't match the lockfile, e.g. after a pull (npm, pnpm, yarn 1)install
Direct dependenciesA dependency is missing or installed outside its range, including in workspacesinstall
Native modulesA .node addon was built for another Node ABI or OS/CPU. Each is loaded in a separate processrebuild <pkg>
Installernode_modules was written by npm, but the project uses pnpm (or similar)clean reinstall
LockfilesMore than one package manager's lockfile, a mismatch with packageManager, or no lockfileby hand
pnpm buildspnpm 10 skipped a package's build scriptspnpm approve-builds

--json gives machine-readable output, and the exit code is 1 when there are errors, so it works in CI too.

git hook

Know when to reinstall, right when it happens

Someone bumps a dependency and you pull. Nobody reinstalls, and an hour later the build breaks in a confusing way. The hook catches the moment the lockfile changes.

  • Silent unless it matters. If no dependency file changed, or node_modules already matches, you see nothing.
  • Warn or auto-install. --mode install runs the install or a targeted rebuild, and never deletes node_modules.
  • Team-wide with husky. It writes to .husky/ so you can commit it, and keeps your existing hooks.
  • Never breaks git. It's skipped in CI, and CLEANINSTALL_SKIP_HOOK=1 skips it once.
$npx cleaninstall-node hook install
$ git checkout release/2.4
Switched to branch 'release/2.4'

📦 cleaninstall-node: dependencies changed (pnpm-lock.yaml)
   ✖ node_modules is out of sync with pnpm-lock.yaml (3 differences)
   → run: pnpm install
   (or: npx cleaninstall-node doctor --fix)
clean

When you really want a fresh start, do it safely

Finds every workspace from package.json or pnpm-workspace.yaml and cleans it in one go.

  • Asks once, with the full list and sizes. Use -y in scripts; CI and pipes don't prompt.
  • Keeps lockfiles by default, so a “clean install” doesn't quietly upgrade your dependencies. Use --lockfiles for a full reset.
  • Knows framework output: .next, .nuxt, .svelte-kit, .astro, .turbo, .vite, coverage and more.
  • Reinstalls with the right tool, detected from packageManager or your lockfile.
  • Dry run and interactive modes, plus config in package.json or .cleaninstallnoderc.
$ npx cleaninstall-node --dry-run

[Dry Run] Would remove:
  dist/  (1.2 MB)
  node_modules/  (293.0 MB)

✅ Cleanup (Dry Run) completed successfully!

📊 Summary:
   - Items would be removed: 2
   - Space to be freed: 294.2 MB
Install

Get cleaninstall-node

Run it once with no install, add it to your project so the git hook works for everyone, or install it globally. Requires Node.js 20+.

$
$
$
GIVE THE WHOLE TEAM THE HOOK

With cleaninstall-node in devDependencies, add a prepare script. Everyone gets the git hook on their next install.

{
  "scripts": {
    "prepare": "cleaninstall-node hook install",
    "doctor": "cleaninstall-node doctor",
    "fresh": "cleaninstall-node -y --install"
  }
}
DOWNLOAD

Prefer a file? Get the package tarball for the latest version, or browse every release.

Upgrading from 2.x

  • Lockfiles are kept by default. Pass --lockfiles to remove them.
  • The CLI asks once before deleting in a terminal. Add -y to scripts; CI and pipes don't prompt.
  • Node.js 20+ is required.

Full list in the changelog.

Copied