icons javascript next js npm packages react js Uncategorized

Find and Remove Unused NPM Packages from Your Project

While building apps in an NPM environment it’s easy to accumulate lots of NPM packages in our app that we don’t even need, these package slows down our build process and make our app bulky.

To manually analyze goto package.json and you might find some packages that you don’t even remember adding, but you can just delete them as you might also not remember if you are using that package in your project or not. For that, we have several tools to automatically scan our project and determine which packages are not being used in our project, so that we can decide which packages to keep and which to remove.

The two most popular tools for scanning are depcheck and npm-check.

Depcheck

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 missing from package.json.

To use depcheck we can install it first, we might install it globally or as a dev dependency in our project and run it by typing depcheck in the terminal.

Or we can just use npx depcheck which is a package runner bundled in npm.

By installing depcheck

npm install -g depcheck
yarn global add depcheck

Now to use it just run the below command and depcheck will start scanning your whole project.

depcheck

Terminal Output

Using npx depcheck

Just type and run the below command in the terminal and it will show all the unused dependencies and devDependencies in your project.

npx depcheck

Terminal Output

Now you can manually remove any package from the given list if you don’t want to use them soon in your project.

For more information on depcheck visit official documentation.

NPM Check

npm-check checks for outdated, incorrect, and unused dependencies in your project.

To learn more about npm-check and its features visit the official documentation, meanwhile, let’s see how to use it.

To use npm-check you can just run it using `npx by running

npx npm-check

Or install it globally or as a dev dependency and use it using npm-check

 npm install -g npm-check

and run npm-check in the terminal.

Terminal Output

The result should look like the screenshot, or something nice when your packages are all up-to-date and in use.

Conclusion

It does not matter which tool you are using but before taking any action, it’s important to note that the lists given by these tools cannot be taken for granted as the packages that you may not directly use in your project it may still be used as dependencies for another package, It’s very important to double check yourself before taking any action.

You should take action progressively by testing that all is ok with your project.

At any point you change package.json you should run or build your project to see if things are still intact.

Thanks for reading this article, we also have a YouTube channel where we upload similar content in video form, please consider having a look.

Related Posts

How To Install and Use Flowbite in Next js

Flowbite is an open-source library of UI components based on the utility-first Tailwind CSS framework featuring dark mode support, a Figma design system, templates, and more. It provides…

Using Notistack in Nextjs | React js

Showing toast messages in react apps is a common feature to add, as it’s one of the quickest ways to give feedback to users. There are many toast…

Using React Feather Icons in Next js

Feather Icons is a collection of sleek and beautiful icons that you can use in your projects in different ways and integrate seamlessly with React-based applications. To use…

Using Bootstrap Icons in Next js | React

Bootstrap Icons is a Free, high-quality, open-source icon library with over 2,000 icons. You can use them as you like SVGs, SVG sprite, or web fonts. We can…

lucide icons

Using Lucide React Icons in Nextjs | React js

Lucide offers a sleek and versatile icon library that seamlessly integrates with your Next.js or React applications. Let’s explore how to leverage Lucide for beautiful, customizable icons: Lucide…

Best toast notification libraries for Next js

One of the most liked aspects of the React Ecosystem is that you can find components and libraries for almost everything you want to implement in your React…

Leave a Reply

Your email address will not be published. Required fields are marked *