32

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?

3 Answers 3

40

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.

3
  • If you've found a better solution, please let me know
    – Reyraa
    Dec 10, 2016 at 12:35
  • When you are asked to choose a version, you can also prefix the selection with a ! and it will automatically update your bower.json with a "resolutions" json.
    – mattliu
    Feb 15, 2017 at 8:45
  • @mattliu Thank you. I'll update my answer to include this
    – Reyraa
    Feb 15, 2017 at 13:43
38

If you would like to install JQuery 2.1.4 strictly and add it to your bower.json dependencies you would go like this

bower install jQuery#2.1.4 --save
1
  • 2
    This does not require modifying bower.json by hand. This should be accept answer.
    – devXen
    Mar 14, 2018 at 9:49
5
  • You need to specify the version in bower.json.
  • Note that using a tilde will automatically resolve to any newer minor version
  • So, specifying ~1.5.x would pull 1.5.1 if it existed
  • To specify an exact version, remove the tilde e.g. specify "1.5.1"
1
  • Thank you. you're right. Here my problem was between angular 1.2.x and 1.5.x which makes a breaking difference. that's why I like to have any patch releases in 1.5.x but not other minor releases.
    – Reyraa
    May 11, 2017 at 9:28

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.