Bower Dependency Resolution and Package Name Conflict Overwrites
0 reputation · 02 Apr 2020, 02:30 UTC
0 reputation · 02 Apr 2020, 02:30 UTC
Bower utilizes a depth-first resolution strategy to select the first matching version listed in bower.json for each dependency. During the installation process, the tool manages a flat dependency tree where only one version of a package can exist in the project.
A specific behavior occurs when multiple dependencies require different versions of the same package, or when package name conflicts arise. In these scenarios, Bower silently overwrites the earlier entry with the most recently resolved version. This creates uncertainty regarding the final state of the bower_components directory when complex dependency graphs are involved.
.bowerrc to prevent silent overwrites and instead trigger a resolution error?31275 reputation · 02 Apr 2020, 12:51 UTC
Bower resolves to a flat tree with one version per package name in bower_components. When the same package is required by multiple dependencies with different version ranges, Bower does not error by default. It silently keeps the version that is resolved last in the current install pass, and an explicit version in the root bower.json overrides transitive requests. There is no .bowerrc option to turn silent overwrites into a hard resolution error.
bower.json is authoritative. A version pinned at the root overrides versions requested by transitive dependencies..bowerrc setting to disable silent overwrites or force a failure on version conflict.resolutions field in root bower.json and explicit pinning.Bower resolves depth-first. The exact priority of a conflict in a single bower install is order-dependent on the traversal of the dependency graph and the order dependencies are listed in bower.json. In practice this is observed as a last-one-wins outcome: the version written last to bower_components during that pass is the one that remains. This is implementation behavior, not a documented deterministic ranking.
Assumption: Bower 1.x. Behavior is deprecated and not guaranteed across forks or old caches.
bower --version
bower install --verbose
ls bower_components
bower list
{
"dependencies": {
"package-name": "1.2.3"
},
"resolutions": {
"package-name": "1.2.3"
}
}
rm -rf bower_components bower.json.lock
bower install
Silent overwrites can cause runtime errors if a dependent relies on an API removed in the winning version.
One diagnostic that changes the recommendation: which Bower version you are running and whether a resolutions block is already present in the root bower.json. If you are on a very old Bower release or using a custom resolver, the traversal order can differ.
Use comments to ask for clarification. Post a solution as an answer.
No question comments on this page.