The Problem I Faced: Losing Track of Unused Packages and Outdated Dependencies
I realized that my project was becoming difficult to manage due to a clutter of unused and outdated packages.
I had installed several packages, some of which I no longer needed, and others were out of date.
The issue arose because I was unsure which packages were actively being used in my code and which ones were just taking up space.
This made it harder to keep the project optimized and maintainable.
Additionally, with packages that I didn’t need anymore, my dependency tree was unnecessarily large, which could also lead to potential issues in performance and security.
I wanted to clean up my project by removing unused dependencies and updating outdated packages.
But, without a clear way to check which packages were in use, I was unsure how to go about it.
To solve this problem, I followed these steps:
npm-check
Tool:The first step I took was to install the npm-check
tool globally.
This tool helps identify which packages are outdated, missing, or unused in my project. I installed it using the following command:
npm install -g npm-check
npm-check
:Once npm-check
was installed, I navigated to my project directory in the terminal and ran the command:
npm-check
This command analyzed my node_modules
folder and package.json
file, generating a report that highlighted the following:
package.json
but still referenced in the code.After running the check, I noticed several packages flagged as “NOTUSED”. For example, packages like mdast-util-toc
, rehype-parse
, and remark
were no longer being used in the code.
The tool suggested that I review my code before removing them, but based on my inspection, I confirmed they were not required.
Since I was confident the unused packages weren’t needed, I uninstalled them with the following commands:
npm uninstall mdast-util-toc
npm uninstall rehype-parse
npm uninstall remark
I repeated this process for all unused packages flagged by the tool.
The tool also notified me of several packages with updates available, such as next
, react
, tailwindcss
, and eslint
.
To ensure my project was up-to-date, I followed the provided commands to update these packages:
```bash
npm install next@15.0.4 --save
npm install react@19.0.0 --save
npm install tailwindcss@3.4.16 --save-dev
npm install eslint@9.16.0 --save-dev
```
This ensured that my project was using the latest versions of these dependencies, reducing the risk of bugs and vulnerabilities.
During the check, I also noticed that the site
package was missing from my package.json
but was still referenced in several files.
Since it was required by my project, I added it back by installing it:
```bash
npm install site --save
```;
After making the changes, I ran my application to ensure everything was still working correctly.
I also ran npm-check
again to confirm that there were no more unused packages and that everything was up-to-date.