2013-12-14 149 views
1

我按照grunt site的文档。执行sudo npm install -g grunt-cli后,我得到了这个输出安装grunt时出现问题

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 
    [email protected] /usr/local/lib/node_modules/grunt-cli 
    ├── [email protected] 
    ├── [email protected] ([email protected]) 
    └── [email protected] ([email protected], [email protected]) 

在此之后,当我做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 

这个我也跟着this link解决我的问题后,但我还是我得到了同样的错误以上。

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" 
     } 
    } 
+0

你有Gruntfile和package.json吗? –

回答

7

您已经安装grunt-cli作为一个全球性的包,但你还需要安装grunt本地。 grunt-cli软件包会安装全局命令行工具,但该命令行工具只会尝试加载本地安装的grunt模块。这样做的目的是为了让人们可以为不同的项目制作多个版本的grunt,你需要将grunt本身作为本地软件包安装在你正在使用的项目中。

从你的页面链接到:

注意,在安装咕噜-CLI不安装繁重任务运行! Grunt CLI的工作很简单:运行已安装在Gruntfile旁边的Grunt版本。这允许多个版本的Grunt同时安装在同一台机器上。

所以你需要有grunt在你的package.json文件的本地依赖性,就像任何其他的模块,哪来你不会在里面列出grunt-cli

+0

我在我的项目中有package.json和Gruntfile.js文件。请看我更新的问题。 – 2619

+0

但是你真的已经安装了'grunt',或者只是把它列在你的package.json中?尝试运行npm install或者特别是npm install [email protected] – loganfsmyth

+0

我已经完成了npm的安装并安装了grunt。但现在我得到这个错误'警告:任务“分钟”未找到。使用--force继续。 因警告而中止。当我运行'grunt min'命令时。 – 2619

0

npm update为我工作。 Grunt必须更新。