Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why does Bower remove my "resolutions" and how do I stop it

Tags:

bower

I have a bower.json file

{
  "name": "example-project",
  "private": true,
  "dependencies": {
    "angular": "1.2.14",
    "angular-scenario": "1.2.14",
    "angular-resource": "1.2.14",
    "angular-ui-router": "0.2.10",
    "angular-strap": "2.0.0"
  }
}

When I run grunt (with grunt-bowercopy or grunt-bower-task) I get an error Fatal error: Unable to find suitable version for angular

When I run bower install it says it doesn't know which version of angular to use:

Unable to find a suitable version for angular, please choose one:
1) angular#1.2.14 which resolved to 1.2.14 and is required by angular-scenario#1.2.14, example-project 
2) angular#>= 1.0.8 which resolved to 1.2.16 and is required by angular-ui-router#0.2.10 
3) angular#~1.2.10 which resolved to 1.2.16 and is required by angular-strap#2.0.0 

Prefix the choice with ! to persist it to bower.json

So that explains why grunt was failing - it had transitive dependencies and didn't know which one to select. So I choose 1 (!1 to persist). Now my bower.json looks like this:

{
  "name": "example-project",
  "private": true,
  "dependencies": {
    "angular": "1.2.14",
    "angular-scenario": "1.2.14",
    "angular-resource": "1.2.14",
    "angular-ui-router": "0.2.10",
    "angular-strap": "2.0.0"
  },
  "resolutions": {
    "angular": "1.2.14"
  }
}

Sweet! I run bower install again. This time it succeeds but removes the "resolutions" part. Now it just works for me without resolutions, but my coworkers will get the same error and have to go through the same process.

Why does it do this? Is there any way to stop it from happening?

-Update-

It seems that this is a bug. See bower issues https://github.com/bower/bower/issues/1061 and https://github.com/bower/bower/issues/1272. Hopefully the issue will get some attention and get resolved.

like image 858
Planky Avatar asked Apr 08 '14 19:04

Planky


1 Answers

Upgrade to Bower 1.4.0 or greater where this issue is resolved.

Previous Answer: A workaround suggested by edeustace (see https://github.com/bower/bower/issues/1061) is to add a script to your build (grunt, gulp, etc) that resets the resolutions as they should be after running bower. It's an ugly solution but should do the trick until the issue gets resolved.

like image 165
Planky Avatar answered Jan 01 '23 19:01

Planky