Bower为什么删除我的"决议",如何阻止它

Pla*_*nky 10 bower

我有一个bower.json文件

{
  "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"
  }
}
Run Code Online (Sandbox Code Playgroud)

当我运行grunt(使用grunt-bowercopygrunt-bower-task)时,我收到错误消息Fatal error: Unable to find suitable version for angular

当我运行bower install它说它不知道使用哪个版本的角度:

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
Run Code Online (Sandbox Code Playgroud)

这就解释了为什么grunt失败了 - 它具有传递依赖性,并且不知道选择哪一个.所以我选择1(!1坚持).现在我的bower.json看起来像这样:

{
  "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"
  }
}
Run Code Online (Sandbox Code Playgroud)

甜!我又跑bower install了 这一次它成功但删除了"决议"部分.现在它对我来说没有解决方案,但我的同事会得到同样的错误,并且必须经历相同的过程.

为什么这样做?有没有办法阻止它发生?

-Update-

看来这是一个bug.请参阅bower问题https://github.com/bower/bower/issues/1061https://github.com/bower/bower/issues/1272.希望这个问题能得到一些关注并得到解决.

Pla*_*nky 1

升级到 Bower 1.4.0 或更高版本即可解决此问题。

上一个答案: edeustace 建议的解决方法(请参阅https://github.com/bower/bower/issues/1061)是将一个脚本添加到您的构建(grunt、gulp 等)中,该脚本会重置分辨率,因为它们应该是在运行凉亭。这是一个丑陋的解决方案,但应该可以解决问题,直到问题得到解决。