什么原因导致'grunt serve'抛出'未找到Bower组件'的错误?

54
我在Windows 7电脑上使用angular-fullstack开始编写Angular应用程序。我使用-g选项安装了一堆npm包,包括grunt-bower-install。运行以下命令创建了一个应用程序:

yo angular-fullstack 应用程序名称

应用程序创建期间没有出现任何异常。成功创建应用程序后,我尝试使用以下命令运行该应用程序:

grunt serve

期望服务器开始运行。但是,“grunt serve”失败并显示以下错误信息:

Running "bower-install:app" (bower-install) task Cannot find where you keep your Bower packages.

We tried looking for a .bowerrc file, but couldn't find a custom directory property defined. We then tried bower_components, but it looks like that doesn't exist either. As a last resort, we tried the pre-1.0 components directory, but that also couldn't be found.

Unfortunately, we can't proceed without knowing where the Bower packages you have installed are.

Fatal error: No Bower components found.

我确实找到了.bowerrc文件,并且它指向app/bower_components。不幸的是,bower_components文件无处可寻。我不确定该文件的内容是否会导致此问题,或者是否有npm包我没有正确安装。
  • 我也使用npm安装了bower *
谢谢。

17
在您应用程序的根目录下运行 bower install ...它将安装依赖项到 app/bower_components,然后应该可以工作。 - doodeec
3
我运行了 "bower install" 命令,结果出现错误提示:"bower ECMDERR Failed to execute "git ls-remote --tags --heads git://github.com/angular/bower-angular.git",返回的退出码是 #128"。为解决该问题,我需要运行命令 --> "git config --global url."https://".insteadOf git://",然后再次运行 "bower install" 即可。 - yantaq
9个回答

70

令人困惑的是,angular-fullstack自带的grunt-bower-install任务不会安装bower组件。它什么都不安装。这个错误是在试图让你知道它找不到bower_components目录,因此无法完成其任务。

要解决此问题,请运行bower install命令。

如果您没有安装Bower,请先运行npm install -g bower命令。


3
我忘了执行 bower install。这让我想起来了。谢谢! - Robin van Baalen
你在哪里运行bower install命令?是在webapp目录的根目录下吗? - basickarl
是的,在您的项目目录中(不一定是根目录),只需运行该命令,组件将安装在名为“bower_components”的目录中,无论 bower.json 位于何处。 - James van Dyke

44

我遇到了相同的问题,以下是我的解决方法:

  1. 安装ruby和compass(yeoman需要这些)
  2. 确认Ruby bin文件夹的路径已添加到%PATH%
  3. 安装Git
  4. 重新启动cmd窗口并在应用程序文件夹中运行"bower install"

之后,grunt serve命令正常工作。 注意:也许只需安装Git并运行bower install即可解决你的问题。


1
我还需要安装Ruby和Compass(根据http://stackoverflow.com/questions/22554220/compass-error-for-command-grunt-server上的特定版本)才能让grunt serve正常工作。 - mekondelta
3
需要指出的是,您需要安装Bower。 - Cyril CHAPON
具体来说,如果您在运行生成器时选择(默认)sass选项,则只需要Ruby和Compass。但是我已经成功地在没有它们的情况下工作了。 - Hilton Shumway

12

我遇到了同样的问题,但只需运行npm install -g bower然后运行bower install即可使grunt serve正常工作。

我不需要执行Olga提到的任何操作。

希望这可以帮助您。


2
她确实说要执行 bower install - Pierre Arlaud

5

npm install -g bower 不会安装 bower 组件,您需要运行 bower install 来安装所有 bower 的组件,然后再运行 grunt serve。这样应该就可以正常工作了。


3
尝试运行bower install。如果出现连接不到git的错误,则可以通过运行以下命令来更改仓库指向位置:
$ git config --global url.https://github.com/.insteadOf git://github.com/ 

这将确保您通过 HTTPS 下载,而不是 Git,如果 Git 导致机构防火墙阻止它。

1

在我的情况下,我添加了sudo才能使它工作。因此,我运行了sudo npm install -g bower,然后运行bower installgrunt serve在我运行它时就可以工作了。


1
Bower安装需要从Git代码库获取软件包,因此您需要在系统中先安装Git应用程序。您可以从此链接https://git-scm.com/downloads下载它。现在,在您下载完成后,可能会有可能没有设置好PATH,所以请进入控制面板->系统和安全->系统->高级系统设置(在左侧),点击它,然后转到环境变量->系统变量->路径,点击编辑,并写下以下路径:
;C:\Users\admin\AppData\Local\Programs\Git\bin; C:\Users\admin\AppData\Local\Programs\Git\cmd .... 好的,上面的路径是Git在我的系统中安装的位置,您可以浏览到Git安装的位置并从“bin”和“cmd”文件夹中选择路径并将其粘贴到变量PATH中。
现在,在设置GIT路径之后,您可以输入命令“$ bower install”,这将安装所有的bower包。

1
npm install -g bower
bower install
grunt serve

对我有用...


-1
npm install -g bower
bower install
grunt serve

已经工作了


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