无法在简单的Yeoman Angular项目中使用grunt

8
尝试通过Yeoman启动一个简单的Angular应用程序,使用此指南中的步骤:http://www.sitepoint.com/kickstart-your-angularjs-development-with-yeoman-grunt-and-bower/,但是在运行gruntgrunt server时出现以下错误:
Loading "Gruntfile.js" tasks...ERROR
Error: Cannot find module 'load-grunt-tasks'
Warning: Task "default" not found. Use --force to continue.

这是我的版本:

yo --version && grunt --version && bower --version
1.1.2<
grunt-cli v0.1.13
grunt v0.4.4
1.3.1

观看此操作的屏幕录像:http://screencast.com/t/4ToPw3SlL2


1
请问您能否发布您的Gruntfile.js文件?它可能存在一些错误的格式。 - przno
当你在项目目录中时,输入 npm list load-grunt-tasks 会发生什么? - Jason Aller
npm 列出 load-grunt-tasks da@0.0.0 c:\workspace\da └── load-grunt-tasks@0.4.0 - dalew75
这是我的Gruntfile.js文件:https://drive.google.com/file/d/0B3J7zzEKdihiWS1nUEY1RU9LNkU/edit?usp=sharing - dalew75
嗨,请选择这个问题的答案。谢谢。 - Henry Neo
3个回答

17

今天我遇到了同样的问题,通过这里的答案解决了它。

基本上,我需要将 npm 更新到最新版本,使用以下命令(随 Node-v0.10.29 包提供的 npm 版本已过时)

npm update npm -g
或者
sudo npm update npm -g (i used this command on my mac)

然后输入这个命令

npm --version (it should show 1.5.0-alpha-4 or later version)

然后输入 "grunt serve" 命令。

grunt serve

如果你仍然遇到问题,那么尝试运行这些命令

npm install 
或者
sudo npm install (i used this command on my mac)

然后再次尝试运行"grunt serve"命令,

grunt serve

这一次,它对我有效了。

如果这个方法不行的话,请尝试这个命令。

bower install (i did not have to use this command)

伟大的Henry Neo,经过漫长的搜索,它终于成功了!谢谢。 - Seralto
嗨Sergio,很高兴能帮忙 :) - Henry Neo

6

在包含你的项目 Gruntfile.js 的目录下运行以下命令:

npm install
npm install -g bower
bower install

这将为您的项目安装所有基于npm和bower的依赖项。
在1:18的录屏中,显示了与至少multimatch相关的安装错误。load-grunt-task依赖于multimatch。

这个没起作用。我尝试更新到最新的npm 1.4.6,但仍然没有成功。 - dalew75
当您使用 npm install 命令时,输出是否以关于日志文件的错误和消息结尾? - Jason Aller
谢谢Jason。我最终通过zip文件手动安装了最新的npm。现在是1.4.6版本。这样做后,我能够创建一个新目录,运行“yo angular”,然后运行“grunt serve”。这会像预期的那样在Chrome中打开Web应用程序。我不清楚通过命令行更新npm的命令。我已经阅读了有关执行“npm install npm”的内容,但没有成功。我从这里获取了zip并解压到我的安装目录中:http://nodejs.org/dist/npm/ - dalew75
使用“sudo npm update npm -g”更新到最新的npm对我很有效。 - Henry Neo

0
安装了本地的"load-grunt-tasks"模块

npm install load-grunt-tasks

替代

npm install -g load-grunt-tasks 

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