5

Just Getting started with grunt, and when I run grunt I get this error

Loading "Gruntfile.js" tasks...ERROR
>> ReferenceError: grunt is not defined

This is my Gruntfile.js

module.exports = function(grunt){
  'use strict';
};

4 Answers 4

7

I had it suddenly happen to me,

'use strict';
module.exports = function(grunt) {
  grunt.initConfig({
    sass: {
      dist: {
        files: {
          'style.css': 'style.scss'
        },
        options: {
          includePaths: ['css/'],
          outputStyle: 'nested'
        }
      }
    },
  });
  grunt.loadNpmTasks('grunt-sass');
  grunt.registerTask('sass', ['sass']);

};

Make sure the loadNpmTasks and registerTask commands are inside the module.export, if they're outside of the scope of that closure grunt won't be defined, so it fails

5

Not entirely sure why, but this resolved that issue:

'use strict';
module.exports = function(grunt){
};
1
  • Just had the same error as you, but using the strict command doesn't solve it for me.
    – Jorre
    Nov 25, 2013 at 14:54
0

I too saw many "grunt not defined" error messages on my terminal.

I grabbed another gruntfile.js from the same directory where I had Node and NPM installed, and replaced the boilerplate gruntfile.js with the other gruntfile.js.

Now, I call Grunt and it works.

0

I had trailing commas in my gruntfile code which was throwing that error. Thank you ReSharper. Hope this helps someone.

   pkg: grunt.file.readJSON('package.json'),
    ngAnnotate: {
        options: {
            singleQuotes: true
        },
        FFApp: {
            files: {
                'Scripts/Angular-Annotated/Annotated.js': ['Scripts/Angular/**/*js']
            }

, (< deleted this)

        }

,(< and this one)

    },

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.