v2/docs/troubleshooting/wsl-better-sqlite3-error.md
Good news! Starting with v2.7.35, claude-flow includes automatic error recovery that handles this issue without manual intervention.
--force)npx claude-flow@alpha init --force
The --force flag enables automatic error recovery and will:
[Error: ENOTEMPTY: directory not empty, rmdir '/home/username/.npm/_npx/xxxxx/node_modules/better-sqlite3']
errno: -39
When running: npx claude-flow@alpha init --force on Windows Subsystem for Linux (WSL)
Note: If you're using v2.7.35+, automatic recovery handles this. Manual fixes below are only needed for older versions or edge cases.
# Clear npm cache
npm cache clean --force
# Remove npx cache directory
rm -rf ~/.npm/_npx
# Retry installation
npx claude-flow@alpha init --force
# Install globally first
npm install -g claude-flow@alpha
# Then run init
claude-flow init --force
# Find the problematic directory
ls -la ~/.npm/_npx/
# Force remove with elevated permissions if needed
sudo rm -rf ~/.npm/_npx/*/node_modules/better-sqlite3
# Clear entire npx cache
rm -rf ~/.npm/_npx
# Retry
npx claude-flow@alpha init --force
# Ensure proper ownership
sudo chown -R $(whoami) ~/.npm
# Fix permissions
chmod -R 755 ~/.npm
# Clear and retry
npm cache clean --force
npx claude-flow@alpha init --force
# Install build tools if missing
sudo apt-get update
sudo apt-get install -y build-essential python3
# Clear cache and retry with rebuild flag
npm cache clean --force
rm -rf ~/.npm/_npx
npx claude-flow@alpha init --force
# Check WSL version
wsl --list --verbose
# Ensure using WSL2 (not WSL1)
wsl --set-version Ubuntu 2
# Use Node 18+ (better-sqlite3 compatibility)
node --version
# Install/update node if needed via nvm
curl -o- https://raw.githubusercontent.com/nvm-sh/nvm/v0.39.0/install.sh | bash
source ~/.bashrc
nvm install 20
nvm use 20
# Retry installation
npx claude-flow@alpha init --force
# Bad: Running from /mnt/c/Users/... (Windows filesystem)
cd /mnt/c/Users/username/project # ❌
# Good: Running from WSL filesystem
cd ~/projects/your-project # ✅
# Copy project to WSL if needed
cp -r /mnt/c/Users/username/project ~/projects/
# Run from WSL filesystem
cd ~/projects/project
npx claude-flow@alpha init --force
~/ not /mnt/c/)npm install -g npm@latest.bashrc:
alias npm-clean="npm cache clean --force && rm -rf ~/.npm/_npx"
Create a script to automate the fix:
#!/bin/bash
# wsl-fix-npx.sh
echo "🔧 Fixing WSL NPX cache issues..."
# Stop any running node processes
pkill -f node || true
# Clean npm cache
echo "📦 Cleaning npm cache..."
npm cache clean --force
# Remove npx cache
echo "🗑️ Removing npx cache..."
rm -rf ~/.npm/_npx
# Fix permissions
echo "🔐 Fixing permissions..."
sudo chown -R $(whoami) ~/.npm
chmod -R 755 ~/.npm
# Verify node/npm
echo "✅ Verifying Node.js..."
node --version
npm --version
echo "🎉 Cleanup complete! Try running your command again."
echo "Command: npx claude-flow@alpha init --force"
Usage:
chmod +x wsl-fix-npx.sh
./wsl-fix-npx.sh
npx claude-flow@alpha init --force
If none of the solutions work, gather this information:
# System info
cat /etc/os-release
node --version
npm --version
wsl --list --verbose # Run from Windows PowerShell
# Error details
npx claude-flow@alpha init --force --verbose 2>&1 | tee error-log.txt
Then report at: https://github.com/ruvnet/claude-flow/issues
If WSL issues persist, consider using Docker:
# Pull claude-flow Docker image (if available)
docker pull ruvnet/claude-flow:latest
# Run in container
docker run -it -v $(pwd):/workspace ruvnet/claude-flow:latest init --force
The ENOTEMPTY error occurs because:
The error code -39 (ENOTEMPTY) means the system tried to remove a directory that still contains files, typically due to: