Best practices for management

  • Try for better Compatibility: Whenever possible try to choose dependency versions that work well together to minimize the need for overrides.
  • Check for Security risks: If you dependencies or any nested dependencies have security vulnerability make sure you update or override it to a secure version.
  • Use Exact Versions: For dependencies with lack of compatible version keep track and use an exact versions that works with other dependency so that you can avoid unexpected or breaking changes in future updates.
  • Documentation: Try to document the working versions and changes made in the package.json file or any other file with respective to the dependency version. Also try to explain the reasons for overrides or other methods used for version changes.
  • Automation is not perfect: If you are using automation tools like npm-check-updates or yarn-upgrade-all then carefully test you project after the automated updates as they might not always handle nested dependencies perfectly.


How to override nested NPM dependency versions?

In projects the packages download and used using npm are called dependency and each dependencies can have their own nested dependencies that also gets downloaded. These nested dependency creates conflicts due to the presence of multiple version of the same dependency. This will lead to issues like compatibility, security vulnerabilities, and unexpected behavior.

To solve that we got multiple ways such as overrides property in package.json file, npm-force-resolutions, npm dedupe, npm-check-updates or yarn-upgrade-all.

Table of Content

  • Manual override in package.json
  • Utilizing npm’s npm-force-resolutions
  • Using npm dedupe(deduplicate)
  • Automation with npm-check-updates or yarn-upgrade-all
  • npm users
  • yarn users
  • Testing and documentation for changes
  • Best practices for management

Similar Reads

Manual override in package.json

In the package.json file the overrides property can be used to add key value pair of dependency and its versions. The package name will be key and the value will be the version. Nesting of dependency as key is used for deeper nested dependency. After adding overrides property install or update the packages to apply the changes....

Utilizing npm’s npm-force-resolutions

You can install npm-force-resolutions package to force installation of a specific version of the dependency. Follow the steps to install and use this:...

Using npm dedupe(deduplicate)

The npm dedupe command used for analyzing and making the project’s dependency tree much shorter by removing unnecessary copies of packages within your project’s dependency tree. It searches for shared dependencies which are packages used by multiple packages in your project and then attempts to move them higher in the tree thus reducing disk space and improving efficiency in some cases....

Automation with npm-check-updates or yarn-upgrade-all

You also have npm-check-updates or yarn-upgrade-all commands that helps you to automate dependency updates, but they does not always handle nested dependency conflicts perfectly. Depending upon the package you are using you can automatically update all your project dependency to the latest versions....

npm users

Step 1: Use the following command to install the npm-check-updates package....

yarn users

Step 1: Install the yarn-upgrade-all package as a dev dependency using the following command....

Testing and documentation for changes

Testing...

Best practices for management

Try for better Compatibility: Whenever possible try to choose dependency versions that work well together to minimize the need for overrides. Check for Security risks: If you dependencies or any nested dependencies have security vulnerability make sure you update or override it to a secure version. Use Exact Versions: For dependencies with lack of compatible version keep track and use an exact versions that works with other dependency so that you can avoid unexpected or breaking changes in future updates. Documentation: Try to document the working versions and changes made in the package.json file or any other file with respective to the dependency version. Also try to explain the reasons for overrides or other methods used for version changes. Automation is not perfect: If you are using automation tools like npm-check-updates or yarn-upgrade-all then carefully test you project after the automated updates as they might not always handle nested dependencies perfectly....

Contact Us