Skip to main content

Command Palette

Search for a command to run...

NPM Tricks I Wish I Knew Sooner

Updated
1 min read

Recently I have been working on migrating an old React application based on react-scripts to support Node.js 18. To make it work, I came across multiple npm tricks that helped solve these issues, so I am going to explain and document them in this blog.

Dependencies Checks

npx depcheck

Analyzes the dependencies in a project to see how each dependency is used, which dependencies are unused, and which dependencies are missing from package.json.

Why Events

npm why package_name

This command helps you understand why a package is installed in your project and where it comes from.

Check Subdependencies

npm ls buffer

Prints all the versions of packages that are installed, as well as their dependencies.

Find Duplicates

npm find-dupes

Runs npm dedupe and outputs all the duplication changes without changing the package tree.

Reduce Duplication

npm dedupe

Searches the local packages tree and attempts to simplify the overall structure by moving dependencies further up the tree, where they can be more effectively shared by multiple dependent packages.

Clean Install

npm ci

If you have already set up projects where you have node_modules and package-lock.json, using this command will remove them and perform a clean install.

Resources:

More from this blog

Sridhar Tech Stories

16 posts

A developer, geek, enthusiast, who loves to solve problems and fix things with technology.I am working on 💻frontend web development with Javascript and I love contributing to 🌟 open source.