Clean up project dependencies — speed up development and build!

Wed, April 30, 2025 - 3 min read
Dependencies slowing down development

Clean up project dependencies — speed up development and build

Every dependency in your project is additional build time, disk space, potential vulnerability, increased application size and risk of version conflicts.

This especially applies to unused dependencies and libraries, which often:

  • Are installed for testing but forgotten,
  • Stop being used but remain in package.json,
  • Duplicate with other packages,
  • Haven’t been updated for years and contain vulnerabilities.

🚨 Why is this a problem?

  • ⏳ Dependencies slow down installation (npm install),
  • 🏗️ Increase project build time,
  • 💾 Bloat the size of node_modules and final bundle,
  • 🐛 Create version conflicts,
  • 🔒 Add security vulnerabilities,
  • 📱 Increase application size for users.

📦 Which dependencies most often hang as “dead weight”

🔹 Production dependencies

  • lodash (if you use modern JS)
  • moment.js (replace with date-fns or native Date)
  • jquery (if you use modern frameworks)
  • axios + fetch simultaneously
  • Polyfills for old browsers (if you don’t support them)

🔹 Outdated bundlers and tools

  • webpack (if you switched to Vite)
  • gulp, grunt (if you use modern bundlers)
  • bower (long outdated)

🔹 Duplicate linters and formatters

  • tslint (replaced by ESLint)
  • jshint, jslint (if you use ESLint)
  • Multiple Prettier configs

🔹 Testing libraries

  • mocha + jest simultaneously
  • karma (if you test in Node.js)
  • protractor (outdated, use Playwright/Cypress)

🔹 CSS preprocessors and styles

  • node-sass (replace with sass)
  • less, stylus (if you use CSS-in-JS)
  • Multiple CSS frameworks simultaneously

🔹 Typing

  • @types/* for libraries that already include types
  • Duplicate types

✅ How to act

1. Analysis of unused dependencies

# Install depcheck
npm install -g depcheck
 
# Run analysis
depcheck
 
# Or use npm-check
npm install -g npm-check
npm-check

2. Check outdated packages

# Check outdated dependencies
npm outdated
 
# Or with more detailed information
npm-check -u

3. Security audit

# Check vulnerabilities
npm audit
 
# Automatic fix
npm audit fix
 
# Force fix (be careful!)
npm audit fix --force

4. Bundle size analysis

# For webpack
npx webpack-bundle-analyzer dist/static/js/*.js
 
# For Vite
npx vite-bundle-analyzer
 
# Universal analyzer
npx bundlephobia

🛠️ Tools for cleanup

Knip — modern tool for finding dead code ⭐

Knip is an advanced tool for finding and removing unused dependencies, exports and files in JavaScript/TypeScript projects.

# Installation
npm install -g knip
 
# Run analysis
knip
 
# Or without installation
npx knip

Knip advantages:

  • 🎯 Accurate analysis — uses entry points and understands project structure
  • 🔌 100+ plugins — support for Astro, Next.js, Vite, Jest, Cypress and many others
  • 📊 Detailed reports — shows unused files, exports and dependencies
  • Fast performance — optimized for large projects and monorepos
  • 🛡️ Security — helps find potential vulnerabilities

💡 Useful tips

  • Conduct regular audits — once a month or before release,
  • Use exact versions in production (npm shrinkwrap),
  • Separate dev and prod dependencies correctly,
  • Prefer lighter alternatives (e.g., date-fns instead of moment),
  • Use tree-shaking to exclude unused code,
  • Try Knip — it often finds what other tools miss,
  • Analyze bundle size — monitor what goes into production.

🔧 Cleanup automation

Add scripts to package.json:

{
  "scripts": {
    "deps:check": "depcheck",
    "deps:knip": "knip",
    "deps:update": "npm-check-updates -u",
    "deps:audit": "npm audit",
    "deps:clean": "npm prune && npm dedupe",
    "bundle:analyze": "npx webpack-bundle-analyzer dist/static/js/*.js"
  }
}

Set up pre-commit hooks:

# Install husky
npm install --save-dev husky
 
# Add hook
echo "npm run deps:audit" > .husky/pre-commit

📝 Conclusion

🔻 Excessive dependencies:

  • slow down development,
  • increase build time,
  • create vulnerabilities,
  • complicate project maintenance,
  • increase application size.

🧹 Regularly review all project dependencies. Remove unused ones, update outdated ones, replace heavy libraries with lighter alternatives. Use modern tools like Knip for more accurate analysis and monitor the size of the final bundle.