Grunt不会启动:“>> ReferenceError: grunt is not defined”?

内容来源于 Stack Overflow,并遵循CC BY-SA 3.0许可协议进行翻译与使用

  • 回答 (1)
  • 关注 (0)
  • 查看 (171)

是NodeJS和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');

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"
}
提问于
用户回答回答于

需要在模块中调用:

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

扫码关注云+社区

领取腾讯云代金券

年度创作总结 领取年终奖励