`Fatal error: Unable to find local grunt.`: why asking for local grunt, if I have a global?
我是node.js的一个noob,尝试使用
我创建了一个虚拟环境,激活了它,全球安装了
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 | $ nodenv NODEENV $ source NODENV/bin/activate (NODEENV)$ npm install -g grunt-cli ... (NODEENV)$ npm install -g grunt ... (NODEENV)$ cd myproject (NODEENV)$ ls myproject Gruntfile.js package.json src test README.md (NODEENV)$ grunt test 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. For more information about installing and configuring grunt, please see the Getting Started guide: http://gruntjs.com/getting-started |
我不明白的是,如果我已经安装了一个全局版本,那么为什么
你也能提出一个解决错误的方法吗?
这是由于NPM的折叠:
- Install it locally if you're going to
require() it.- Install it globally if you're going to run it on the command line.
gruntfile本身依赖于可用的
1 | $ npm install grunt |
而且,使用
1 | $ npm install -g grunt-cli |
但是,要同时安装这两个文件夹,必须在两个文件夹中都安装它。
从项目目录运行
这就是它的工作方式。你总是需要:
1 2 | npm install -g grunt-cli npm install grunt |