2013-11-27 10 views
18

Ich bin neu bei NodeJS und Grunt und ich bemühe mich, dass das funktioniert. Hier ist, was ich bekommen:Grunt startet nicht: ">> ReferenceError: grunt ist nicht definiert"

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

Aborted due to warnings. 

Hier ist mein Gruntfile:

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

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

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

Und hier ist mein 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" 
} 

Oh, und ich bin mit dieser auf einem Debian Wheezy.

Wenn Sie eine Idee haben, lassen Sie es mich wissen. Vielen Dank Jungs!

+0

Führen Sie den Befehl aus dem gleichen Verzeichnis wie Ihre Gruntfile? –

+0

Auch ich denke nicht, dass dies einen Unterschied macht. Aber ich denke, Ihre Registrierungsaufgaben sollten so aussehen: 'grunt.registerTask ('default', ['compass']);'. –

Antwort

38

Sie rufen grunt.loadNpmTasks und grunt.registerTask aus einem Bereich, in dem grunt nicht definiert ist. Sie müssen sie innerhalb der Funktion module.exports aufrufen:

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

Es funktioniert! Vielen Dank! :) – Bertrand

Verwandte Themen