2013-11-27 3 views
18

Я новичок в NodeJS и Grunt, и я изо всех сил стараюсь сделать эту работу. Вот что я получаю:Grunt не запускается: «>> ReferenceError: 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'); 

А вот мой package.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 хриплый.

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

+0

Вы используете команду из той же директории, что и ваш файл Gruntfile? –

+0

Также я не думаю, что это имеет значение. Но я думаю, что ваши задачи реестра должны быть такими: 'grunt.registerTask ('default', ['compass']);'. –

ответ

38

Вы вызываете 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'); 
}; 
+0

Это работает! Большое вам спасибо! :) – Bertrand

Смежные вопросы