我按照grunt网站上的文档.执行后sudo npm install -g grunt-cli
我得到了这个输出
npm http GET https://registry.npmjs.org/grunt-cli npm http 304 https://registry.npmjs.org/grunt-cli npm http GET https://registry.npmjs.org/findup-sync npm http GET https://registry.npmjs.org/nopt npm http GET https://registry.npmjs.org/resolve npm http 304 https://registry.npmjs.org/resolve npm http 304 https://registry.npmjs.org/findup-sync npm http 304 https://registry.npmjs.org/nopt npm http GET https://registry.npmjs.org/abbrev npm http GET https://registry.npmjs.org/glob npm http GET https://registry.npmjs.org/lodash npm http 304 https://registry.npmjs.org/abbrev npm http 304 https://registry.npmjs.org/glob npm http 304 https://registry.npmjs.org/lodash npm http GET https://registry.npmjs.org/graceful-fs npm http GET https://registry.npmjs.org/inherits npm http GET https://registry.npmjs.org/minimatch npm http 304 https://registry.npmjs.org/minimatch npm http 304 https://registry.npmjs.org/inherits npm http 304 https://registry.npmjs.org/graceful-fs npm http GET https://registry.npmjs.org/lru-cache npm http GET https://registry.npmjs.org/sigmund npm http 304 https://registry.npmjs.org/sigmund npm http 304 https://registry.npmjs.org/lru-cache npm http GET https://registry.npmjs.org/sigmund/-/sigmund-1.0.0.tgz npm http 200 https://registry.npmjs.org/sigmund/-/sigmund-1.0.0.tgz /usr/local/bin/grunt -> /usr/local/lib/node_modules/grunt-cli/bin/grunt grunt-cli@0.1.11 /usr/local/lib/node_modules/grunt-cli ??? resolve@0.3.1 ??? nopt@1.0.10 (abbrev@1.0.4) ??? findup-sync@0.1.2 (lodash@1.0.1, glob@3.1.21)
在此之后,当我这样做时,grunt
我收到此消息
grunt-cli: The grunt command line interface. (v0.1.11) 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
在此之后我也按照这个链接来解决我的问题,但我仍然得到上面相同的错误.
UPDATE
Gruntfile.js
module.exports = function () { grunt.initConfig({ min: { dist: { src: 'file-one.js', dest: 'file-one.min.js' } } }); }
package.json文件
{ "name": "grunt", "version": "0.1.0", "devDependencies": { "grunt": "~0.1.11", "grunt-contrib-jshint": "~0.6.3", "grunt-contrib-nodeunit": "~0.2.0", "grunt-contrib-uglify": "~0.2.2" } }
loganfsmyth.. 7
您已安装grunt-cli
为全局程序包,但还需要在grunt
本地安装.该grunt-cli
软件包安装了一个全局命令行工具,但该命令行工具只是尝试加载本地安装grunt
模块.这样做是为了允许人们为不同的项目拥有多个版本的grunt,你需要将grunt本身安装为你正在处理的项目中的本地包.
从您链接到的页面:
请注意,安装grunt-cli不会安装Grunt任务运行器!Grunt CLI的工作很简单:运行已安装在Gruntfile旁边的Grunt版本.这允许多个版本的Grunt同时安装在同一台机器上.
所以你需要grunt
在package.json文件中作为本地依赖项,就像任何其他模块一样,你不会grunt-cli
在那里列出.
您已安装grunt-cli
为全局程序包,但还需要在grunt
本地安装.该grunt-cli
软件包安装了一个全局命令行工具,但该命令行工具只是尝试加载本地安装grunt
模块.这样做是为了允许人们为不同的项目拥有多个版本的grunt,你需要将grunt本身安装为你正在处理的项目中的本地包.
从您链接到的页面:
请注意,安装grunt-cli不会安装Grunt任务运行器!Grunt CLI的工作很简单:运行已安装在Gruntfile旁边的Grunt版本.这允许多个版本的Grunt同时安装在同一台机器上.
所以你需要grunt
在package.json文件中作为本地依赖项,就像任何其他模块一样,你不会grunt-cli
在那里列出.