Grunt is not defined

假装没事ソ 提交于 2019-12-23 09:49:11

问题


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';
};

回答1:


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




回答2:


Not entirely sure why, but this resolved that issue:

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



回答3:


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.




回答4:


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)

    },


来源:https://stackoverflow.com/questions/16850650/grunt-is-not-defined

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!