how to force bower to install a certain version of dependency

Reyraa picture Reyraa · Feb 8, 2016 · Viewed 40.9k times · Source

Assume a bower.json file in which dependencies are like

"dependencies": {
    "angular": "~1.5.x",
    "angular-routing": "*",
    "ngDialog": "*",
    "requirejs": "*"
}

because angular-routing requires another version of angular (say 1.2.x), bower prompts me to choose a version.

How could I force bower to install angular ~1.5.x automatically?

Answer

Reyraa picture Reyraa · Feb 8, 2016

I figured out the answer. I'm sharing for others:

If I add the dependency with my favorite version to resolutions in bower.json, Bower will automatically install it. Here is my updated bower.json:

"dependencies": {
  "angular": "~1.5.x",
  "angular-routing": "*",
  "ngDialog": "*",
  "requirejs": "*"
},
"resolutions": {
  "angular": "~1.5.x"
}

More information here.

Update:
As Mattliu mentioned in comments, it's possible to answer with ! when any library asks for another version of an already installed dependency. this way you'll keep existing version and also npm creates resolution config automatically.