与grunt安装有问题
我跟着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
I我收到这个消息
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" } }
你已经安装了grunt-cli
作为一个全局包,但你也需要在本地安装grunt
。 grunt-cli
软件包会安装一个全局命令行工具,但该命令行工具只是试图加载本地安装的grunt
模块。 这是为了让人们有不同的项目的多个版本的Grunt,你需要有grunt本身作为本地包安装在你正在工作的项目。
从您链接到的页面:
请注意,安装grunt-cli不会安装Grunt任务运行器! Grunt CLI的工作很简单:运行已安装在Gruntfile旁边的Grunt版本。 这允许多个版本的Grunt被同时安装在同一台机器上。
所以你需要在你的package.json文件中作为一个本地依赖,就像任何其他模块一样,你不会在那里列出grunt-cli
。
npm update
为我工作。 咕噜必须更新。