我已经使用 grunt 命令全局安装了 grunt-clisudo npm install -g grunt...

我的工作文件夹是`/opt/web',请不要问为什么:)

检查 `/opt/web' 中的 grunt 版本有效:

$ grunt --version
grunt-cli v0.1.13

但是,我实际上无法从那里运行 grunt 任务:
$ grunt
grunt-cli: The grunt command line interface. (v0.1.13)

Fatal error: Unable to find local grunt.

If you're seeing this message, either a Gruntfile wasn't found or grunt
hasn't been installed locally to your project.

如果我在本地安装 grunt,它会要求在本地安装它的所有依赖项(已经在全局安装(!))。

这种行为对我来说似乎很奇怪。

我的问题是 :

这是错误还是功能?这是设计使 grunt 只想使用本地安装的东西吗?

最佳答案

这是设计使然。请参阅 grunt-cli readme

除了查找并运行 grunt 的本地副本外,cli 不执行任何操作。

这意味着每个项目都可以使用项目指定的 grunt 版本,并且知道/测试可以正常工作。考虑到 grunt 可以做的关键事情的数量,这个兼容性 promise 是一个大问题。

Node 站点上还有一个 good blog post ,它更多地讨论了模块安装位置。

关于javascript - 为什么 grunt 在全局安装时不起作用?,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/24263445/

10-12 07:39
查看更多