68

I have a project that depends on both:

  • jquery ~1.9.1
  • another project which in turn depends on jquery >=1.7.2

But when I run bower install, it ends up installing jquery 2.0.2. This seems broken.

How do I either (a) make it correctly solve the constraints or (b) explicitly force a final version to be installed (workaround)?

Yang
  • 15,457
  • 13
  • 99
  • 140

2 Answers2

114

You can add resolutions to the object in your bower.json file and specify the component name & version to automatically resolve the conflict when running bower commands. Like this:

{
  "name": "project-x",
  "private": true,
  "dependencies": {
    "bootstrap-sass": "~3.3.7",
    "modernizr": "~2.8.3",
    "jquery": "~1.11.3"
  },
  "devDependencies": {},
  "resolutions": {
    "jquery": "~1.11.3"
  }
}

Also you can run bower install and when bower will ask for "suitable version" (if interactive mode is on), prefix choice with !, so bower will save your choice into bower.json file.

Rakhat
  • 4,563
  • 3
  • 38
  • 49
  • 2
    This solution doesn't work for me. It doesn't seem to make a difference. Does it require a certain version of Bower and mine happens to be too old (it's installed from npm, so whatever that version is). – Hans Jan 09 '15 at 23:53
  • @Hans try to update bower running: npm update -g bower – Rakhat Jan 12 '15 at 06:00
  • Great answer. This should be marked as correct. Putting ! in front of the choice was extra helpful. – Michael Cole Mar 25 '15 at 10:29
  • 3
    To add to @neilhem answer: bower install will not ask "suitable version" if interactive mode is off. [more information](http://bower.io/docs/api/#non-interactive-mode) – Shibbir Ahmed Nov 23 '15 at 14:33
  • Anything like this for npm (package.json)? – Alon Amir Apr 05 '16 at 09:38
  • 2
    @AlonAmir npm uses nested dependency tree. More here http://stackoverflow.com/questions/18641899/what-is-the-difference-between-bower-and-npm – Rakhat Apr 05 '16 at 12:02
  • You can also save your resolution typing the chose number + !, eg: 2! – felipekm Dec 01 '16 at 14:05
0

use --force-latest

enter link description here

posix99
  • 347
  • 3
  • 13