Grunt не запускается: ">> ReferenceError: grunt не определен"

Я новичок в NodeJS и Grunt, и я изо всех сил стараюсь сделать эту работу. Вот что я получаю:

$> grunt
Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: grunt is not defined
Warning: Task "default" not found. Use --force to continue.

Aborted due to warnings.

Здесь мой Gruntfile:

module.exports = function(grunt) {
        grunt.initConfig({
                compass: {
                        dist: {
                                options: {
                                        config: 'config/config.rb'
                                }
                        }
                }
        });
};

grunt.loadNpmTasks('grunt-contrib-compass');

grunt.registerTask('default', 'compass');

И вот мой пакет .json:

{
  "name": "tests",
  "version": "0.0.0",
  "description": "Grunt Tests",
  "main": "index.js",
  "devDependencies": {
    "grunt": "~0.4.2",
    "grunt-contrib-compass": "~0.6.0",
    "grunt-contrib-watch": "~0.5.3",
    "grunt-cli": "~0.1.11"
  },
  "scripts": {
    "test": "grunt compass"
  },
  "repository": {
    "type": "git",
    "url": "https://github.com/Bertrand31/grunttests.git"
  },
  "keywords": [
    "Grunt",
    "NodeJS",
    "NPM",
    "SASS",
    "Compass"
  ],
  "author": "Bertrand Junqua",
  "license": "GPL",
  "bugs": {
    "url": "https://github.com/Bertrand31/grunttests/issues"
  },
  "homepage": "https://github.com/Bertrand31/grunttests"
}

О, и я запускаю это на Debian Wheezy.

Если у вас есть идеи, сообщите мне. Большое спасибо, ребята!

Ответы

Ответ 1

Вы вызываете grunt.loadNpmTasks и grunt.registerTask из области, где grunt не определен. Вам нужно будет вызвать их в функции module.exports:

module.exports = function(grunt) {
    grunt.initConfig({
            compass: {
                    dist: {
                            options: {
                                    config: 'config/config.rb'
                            }
                    }
            }
    });

    // Call these here instead, where the variable grunt is defined.
    grunt.loadNpmTasks('grunt-contrib-compass');

    grunt.registerTask('default', 'compass');
};