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.
Syntax:
{
"overrides": {
"<dependency_name>": {
"<nested_dependency_name>": "<exact_version_or_range>"
}
}
}
- dependency_name: It’s the main dependency who’s nested dependency you want to change.
- nested_dependency_name: This will be the name of the nested dependency that we want to target.
- exact_version_or_range: You can provide exact version or a range of version of the dependency to override.
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