无法找到适合的angular版本 - bower安装

51

我已经设置好了我的Angular应用程序,所以当它被推送到Heroku时,它会运行bower install。然而,由于版本问题,我遇到了错误。

当我在本地运行bower install时,我会看到这个:

Unable to find a suitable version for angular, please choose one:                                                                           
    1) angular#1.2.16 which resolved to 1.2.16 and is required by angular-resource#1.2.16                                                   
    2) angular#1.2.23 which resolved to 1.2.23 and is required by angular-cookies#1.2.23                                                    
    3) angular#>= 1.0.8 which resolved to 1.2.25 and is required by angular-ui-router#0.2.10                                                
    4) angular#^1 which resolved to 1.2.25 and is required by angular-ui-codemirror#0.1.6                                                   
    5) angular#~1.2.2 which resolved to 1.2.25 and is required by splitter#f5c2195050                                                       
    6) angular#>=1.0.6 which resolved to 1.2.25 and is required by angular-elastic#2.4.0                                                    
    7) angular#~1.2 which resolved to 1.2.25 and is required by angular-nanoscroller#0.2.1                                                  
    8) angular#~1.2.9 which resolved to 1.2.25 and is required by angular-sockjs#0.0.1Prefix the choice with ! to persist it to bower.json  

? Answer::  

我该怎么办 - 实际上我需要 Angular 的 1.3 版本,因为它有防抖功能。

我的 bower.json 文件长这样:

{
  "name": "myapp",
  "version": "0.0.1",
  "dependencies": {
    "json3": "~3.3.1",
    "es5-shim": "~3.1.0",
    "angular-resource": "1.2.16",
    "angular-sanitize": "1.2.16",
    "angular-animate": "1.2.16",
    "angular-ui-router": "~0.2.10",
    "jquery": "~2.1.1",
    "angular-ui-codemirror": "~0.1.6",
    "splitter": "*",
    "angular-cookies": "~1.2.23",
    "angular-elastic": "~2.4.0",
    "angular-local-storage": "~0.0.7",
    "chance": "~0.5.6",
    "nanoscroller": "~0.8.4",
    "angular-nanoscroller": "~0.2.1",
    "angular-sockjs": "~0.0.1"
  }
}
6个回答

77

将您当前的Angular依赖项更新到1.3.x,并添加一个解决方案以抑制提示:

{
  "name": "myapp",
  "version": "0.0.1",
  "dependencies": {
    "angular": "~1.3.x",
    "angular-animate": "~1.3.x",
    "angular-cookies": "~1.3.x",
    "angular-resource": "~1.3.x",
    "angular-sanitize": "~1.3.x",
    "angular-ui-router": "~0.2.10",
    "angular-ui-codemirror": "~0.1.6",
    "angular-elastic": "~2.4.0",
    "angular-local-storage": "~0.0.7",
    "angular-nanoscroller": "~0.2.1",
    "angular-sockjs": ">=0.0.1",
    "json3": "~3.3.1",
    "es5-shim": "~3.1.0",
    "jquery": "~2.1.1",
    "splitter": "*",
    "chance": "~0.5.6",
    "nanoscroller": "~0.8.4"
  },
  "resolutions": {
    "angular": "~1.3.x"
  }
}

抱歉,你能告诉我使用旧版Angular的angular-ui-router (#0.2.10)是否会有任何问题吗?我的疑问是,我是否可以每次盲目地选择最新版本? - Asim K T
@AsimKT 你有找到应对这些问题的策略吗?有时候这真的很令人沮丧,因为你会发现你正在使用一个依赖于旧版 Angular 的模块,而另一个开发人员添加了依赖于更新版本的模块,两者都对你的项目非常重要!我想知道其他团队是如何处理这个问题的! - Willa
不,我没有。如果不是主要版本更改,我认为使用新版本是可以的。我的项目需要一个插件,有这个问题。我使用了最新的依赖库,它运行得很好。尽管我在他们的仓库中提出了一个问题来升级版本并且他们也做到了。你说得对,我们都会面临这些问题! - Asim K T

20

这里有一个非常好的解释和问题解决方案:

bower-resolutions

以下是某些行的参考复制粘贴:

当您通过Bower为应用程序指定依赖项时,一些包可能依赖于同一库的不同版本。 您将不得不解决应用程序实际需要的库的版本。 换句话说,您打破了关系链。 但是,您不希望每次都打破它,因此请保存您的选择。

当您运行bower install时,解决过程是交互式的。 当Bower识别到有两个包依赖于不同版本的包时,它将列出所有这些版本并询问:

输入图像描述

提示中的下一行非常方便。 它读取:

输入图像描述

太棒了! 因此,如果我输入!2,我的选择将保存在bower.json中。 具体来说,它将添加一个解析项:

输入图像描述

现在,下次运行bower install时,不会再出现交互式问题,因为我已经解决了我的应用程序的ember版本应该是1.5.1。


9

您应该更新Bower(这对我有用):

bower update

5
删除您的 /bower_components 目录并重新运行 bower install 即可解决问题。虽然这是个曲线救国的方法,但确实有效!

1
你可以运行安装命令,当它提示选择版本时,使用感叹号(!)作为选项的前缀。例如,!3表示第三个选项。 然后,这将被添加到你的应用程序的bower.json文件中,并解决冲突。
希望这能帮到你。

0

首先尝试这个:
npm install -g bower

如果上述解决方案不起作用,则尝试:

bower update
对我有用。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接