有咕噜声安装问题

时间:2013-12-14 17:29:57

标签: node.js gruntjs

我按照grunt site上的文档进行操作。执行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

在此之后我也跟着this link解决了我的问题,但我仍然遇到了同样的错误。

更新

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

2 个答案:

答案 0 :(得分:7)

您已将grunt-cli安装为全局程序包,但您还需要在本地安装gruntgrunt-cli包安装了一个全局命令行工具,但该命令行工具只是尝试加载本地安装的grunt模块。这样做是为了让人们为不同的项目拥有多个版本的grunt,你需要将grunt本身安装为你正在处理的项目中的本地包。

从您关联的页面:

  

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

因此,您需要在package.json文件中将grunt作为本地依赖项,就像任何其他模块一样,您不会在其中列出grunt-cli

答案 1 :(得分:0)

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