DEV Community


Remove unused npm modules from package.json

I poopcode.
Originally published at on ・1 min read

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.

Discussion (1)

guhkun13 profile image
name cannot be blank • Edited

so i created this script to remove ALL UNUSED deps, (works in unix):