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
  • 16,037
  • 15
  • 100
  • 142
  • Ticket: https://github.com/bower/bower/issues/540 – Sindre Sorhus Jun 20 '13 at 12:04
  • you would have 2 projects here - so one would get one version of jQ and the other a different version so I am thinking you need more detail in your question. – landed Mar 01 '14 at 21:32
  • Have you found a solution to this problem, as I am having the exact same thing and neilhem's solution doesn't work for me (as in, it didn't make any difference)? – Hans Jan 09 '15 at 23:51
  • my work around is run `bower install jQuery#2.1.4 --save` – zx1986 Sep 08 '16 at 07:06

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,783
  • 4
  • 40
  • 50
  • 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
  • 356
  • 3
  • 13