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:
npm install
),node_modules
and final bundle,lodash
(if you use modern JS)moment.js
(replace with date-fns
or native Date)jquery
(if you use modern frameworks)axios
+ fetch
simultaneouslywebpack
(if you switched to Vite)gulp
, grunt
(if you use modern bundlers)bower
(long outdated)tslint
(replaced by ESLint)jshint
, jslint
(if you use ESLint)mocha
+ jest
simultaneouslykarma
(if you test in Node.js)protractor
(outdated, use Playwright/Cypress)node-sass
(replace with sass
)less
, stylus
(if you use CSS-in-JS)@types/*
for libraries that already include types# Install depcheck
npm install -g depcheck
# Run analysis
depcheck
# Or use npm-check
npm install -g npm-check
npm-check
# Check outdated dependencies
npm outdated
# Or with more detailed information
npm-check -u
# Check vulnerabilities
npm audit
# Automatic fix
npm audit fix
# Force fix (be careful!)
npm audit fix --force
# For webpack
npx webpack-bundle-analyzer dist/static/js/*.js
# For Vite
npx vite-bundle-analyzer
# Universal analyzer
npx bundlephobia
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:
npm shrinkwrap
),date-fns
instead of moment
),{
"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"
}
}
# Install husky
npm install --save-dev husky
# Add hook
echo "npm run deps:audit" > .husky/pre-commit
🔻 Excessive dependencies:
🧹 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.