Get "PHP 8 in a Nuthshell" (Soon includes PHP 8.4)
Amit Merchant

Amit Merchant

A blog on PHP, JavaScript, and more

Identify unused npm packages in your project

If you’re working on a large codebase, chances are you might have installed a lot of npm packages in your project. And you might have used some of them just for the sake of trying them out. But, you might have forgotten to remove them from your package.json file.

These unused packages can unnecessarily increase the bundle size of your project. So, it’s better to remove them from your project.

Here’s how you can identify the unused npm packages in your project.

Essentially, you can use npx for this. npx is a tool that lets you execute npm packages without installing them globally.

In this case, we’re going to use the depcheck npm package that identifies unused npm packages in your project.

So, if you want to identify the unused npm packages in your project, you can run the following command in your terminal.

npx depcheck

And that’s it! This will list all the unused npm packages in your project. You can then remove them from your package.json file and run npm install to remove them from your node_modules directory.

Here’s how the output looks like.

npx depcheck

Like this article?

Buy me a coffee

👋 Hi there! I'm Amit. I write articles about all things web development. You can become a sponsor on my blog to help me continue my writing journey and get your brand in front of thousands of eyes.

Comments?