Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove redundant/unused dependencies from package.json?

I know it has been asked before, but depcheck doesn't seem to work for me at all. It gives me a ton of false alerts aparts from having to configure it for "config-only" libs like babel, eslint etc.

What is your approach if you get a task like it? Is there any best practice you could recommend me?

Thank you!

like image 407
TheGabornator Avatar asked Mar 11 '19 14:03

TheGabornator


People also ask

How do I remove extra dependencies from package json?

You can use npm-prune to remove extraneous packages. Extraneous packages are packages that are not listed on the parent package's dependencies list. If the --production flag is specified or the NODE_ENV environment variable is set to production, this command will remove the packages specified in your devDependencies.

How do I remove unused modules from package json?

json. To identify the unused package, just run npx depcheck in the project root directory. Next step is to uninstall the npm packages using npm uninstall command. The post Remove unused npm modules from package.

How do I remove dependencies from package lock?

To remove a dev dependency, you need to attach the -D or --save-dev flag to the npm uninstall, and then specify the name of the package. You must run the command in the directory (folder) where the dependency is located.


1 Answers

The answer is npm-check.

npm i -g npm-check

Then enter the directory of you project and run the tool

cd my-app
npm-check


some-package 😕  NOTUSED?
             To remove this package: npm uninstall --save some-package
like image 140
Mestre San Avatar answered Sep 18 '22 05:09

Mestre San