首页
学习
活动
专区
工具
TVP
发布
社区首页 >问答首页 >Grunt未启动:">> ReferenceError: grunt is not defined“

Grunt未启动:">> ReferenceError: grunt is not defined“
EN

Stack Overflow用户
提问于 2013-11-27 23:57:12
回答 1查看 16.7K关注 0票数 19

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

下面是我的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"
}

哦,我在Debian Wheezy上运行这个。

如果你有任何想法,请告诉我。非常感谢各位!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2013-11-28 00:20:34

您正在从未定义grunt的作用域调用grunt.loadNpmTasksgrunt.registerTask。您需要在module.exports函数中调用它们:

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');
};
票数 40
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/20247147

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档