DEV Community 👩‍💻👨‍💻

DEV Community 👩‍💻👨‍💻 is a community of 964,423 amazing developers

We're a place where coders share, stay up-to-date and grow their careers.

Create account Log in
Cover image for How to check for missing, unused, or out-of-date JavaScript dependencies
Kate
Kate

Posted on

How to check for missing, unused, or out-of-date JavaScript dependencies

Managing dependencies is very important to developing and maintaining a JavaScript application. Here are three quick tips to help with checking for missing, unused, or out-of-date dependencies!

Want to check a project for dependencies missing from the package.json?

Use depcheck!

Install the Depcheck tool to analyze JavaScript projects for dependencies missing from the package.json.

console output

  • Any npm packages that are missing from the package.json file and the associated JavaScript file path where the package is used are listed. The packages can then be installed using the npm-install command.

Want to check a project for unused dependencies?

Use depcheck!

Depcheck also analyzes JavaScript projects for unused dependencies.

console output

  • The unused npm packages are listed and it is safe to remove these from the project by running the npm-uninstall command.

Want check a project for out-of-date dependencies?

Use npm-outdated!

This command will check the registry and compare with the versions specified in the package.json file. Simply run the command npm outdated in the same directory as the project package.json.

Given this package.json:

{
  "@material-ui/core": "^4.10.0",
  "@okta/okta-react": "1.1.4",
  "@testing-library/jest-dom": "^4.2.4",
  "@testing-library/react": "^9.3.2",
  "@testing-library/user-event": "^7.1.2",
  "axios": "^0.19.2"
}
Enter fullscreen mode Exit fullscreen mode

Here is the npm outdated output:
console output

  • Red means update now -> A newer version is available matching the specified package.json version so this should be updated now.

  • Yellow means use caution -> A newer version is available above the specified package.json version. Make sure to test your application with the higher package version to ensure there are no breaking changes introduced when updating.

  • Use the npm-update command to update the dependencies accordingly.

Cover image by Allie on Unsplash

Top comments (0)

"I made 10x faster JSON.stringify() functions, even type safe"

☝️ Must read for JS devs