-3

I am new to Grunt and have been struggling all day to make this work: This is my Gulpfile.js:

'use strict';

// Time how long tasks take. Can help when optimizing build times
require('time-grunt')(grunt);

// Automatically load required Grunt tasks
require('jit-grunt')(grunt);

module.exports = function(grunt) {
    // Define the configuration for all the tasks
    grunt.initConfig({
        pkg: grunt.file.readJSON('package.json'),

        // Make sure code styles are up to par and there are no obvious mistakes
        jshint: {
            options: {
                jshintrc: '.jshintrc',
                reporter: require('jshint-stylish')
            },

            all: {
                src: [
                    'Gruntfile.js',
                    'app/scripts/{,*/}*.js'
                ]
            }
        }
    });

    grunt.registerTask('build', [
        'jshint'
    ]);

    grunt.registerTask('default', ['build']);
};

This my package.json:

{
  "name": "conFusion",
  "private": true,
  "devDependencies": {
    "grunt": "^1.0.1",
    "grunt-contrib-jshint": "^1.0.0",
    "jit-grunt": "^0.10.0",
    "jshint-stylish": "^2.2.1",
    "time-grunt": "^1.4.0"
  },
  "engines": {
    "node": ">=0.10.0"
  }
}

And this is the error message i get:

grunt build

Loading "Gruntfile.js"

tasks...ERROR >> ReferenceError: grunt is not defined

Warning: Task "build" not found.Use--force to continue.

Aborted due to warnings.

Pls guys, I need help. I am working on windows 10, so am using the command line there.

Bahadir Tasdemir
  • 10,325
  • 4
  • 49
  • 61
Gabriel Amaizu
  • 119
  • 1
  • 1
  • 5
  • 5
    You are using GRUNT and not GULP – Weedoze Sep 08 '16 at 07:01
  • You probably need to install grunt first – Bart K Sep 08 '16 at 07:03
  • `grunt` is passed as argument to the exported function but you are trying to access it *outside* of that function. Move the `require` calls inside the function. This has nothing to do with `grunt` specifically, but with *variable scope* in JavaScript. You might want to take a look at [What is the scope of variables in JavaScript?](http://stackoverflow.com/q/500431/218196) – Felix Kling Sep 08 '16 at 07:03
  • Thanks, it worked well – Gabriel Amaizu Sep 08 '16 at 07:07

1 Answers1

1
 module.exports = function(grunt) {

That is where you define a grunt variable. It is an argument to the function you created.

But you try to use it here:

 require('time-grunt')(grunt);

and here:

 require('jit-grunt')(grunt);

This is outside the function where the variable does not exist.

Move those lines inside the function.

Quentin
  • 914,110
  • 126
  • 1,211
  • 1,335