DEV Community

Poopcoder
Poopcoder

Posted on • Originally published at poopcode.com on

Remove unused npm modules from package.json

Depcheck is a tool for analyzing the dependencies in a project to see: how each dependency is used, which dependencies are useless, and which dependencies are unused from package.json. To identify the unused package, just run npx depcheck in the project root directory.

> npx depcheck


npx: installed 146 in 88.761s
Unused dependencies
* express-validator
Enter fullscreen mode Exit fullscreen mode

Next step is to uninstall the npm packages using npm uninstall command.

npm uninstall express-validator
npm WARN retina-backend@1.0.0 No repository field.
npm WARN optional SKIPPING OPTIONAL DEPENDENCY: fsevents@2.1.2 (node_modules/fsevents):
npm WARN notsup SKIPPING OPTIONAL DEPENDENCY: Unsupported platform for fsevents@2.1.2: wanted {"os":"darwin","arch":"any"} (current: {"os":"linux","arch":"x64"})

removed 2 packages and audited 626 packages in 12.337s

24 packages are looking for funding
  run `npm fund` for details

found 24150 vulnerabilities (24147 low, 3 high)
  run `npm audit fix` to fix them, or `npm audit` for details
Enter fullscreen mode Exit fullscreen mode

The post Remove unused npm modules from package.json appeared first on Poopcode.

Top comments (3)

Collapse
 
batbrain9392 profile image
Debmallya Bhattacharya

It's not really 100% accurate. Firstly, it lists all devDependencies as unused. Secondly, it listed @nrwl/angular and tslib as unused in an Nx+Angular project, both of which are required.

Collapse
 
angelalexqc profile image
Ángel Quiroz • Edited

Exactly, is like build process deps resolutions, the tool works for me for solve a deps conflict with husky and older versions of redux-devtools, my point its this tools works in many use cases.
👍🏻

Collapse
 
guhkun13 profile image
name cannot be blank • Edited

so i created this script to remove ALL UNUSED deps, (works in unix): dev.to/guhkun13/comment/1eak1