> ReferenceError: grunt is not defined"-6ren"> > ReferenceError: grunt is not defined"-我是 NodeJS 和 Grunt 的新手,我正在努力完成这项工作。这是我得到的: $> grunt Loading "Gruntfile.js" tasks...ERROR >> Reference-6ren">
gpt4 book ai didi

node.js - Grunt 无法启动 : ">> ReferenceError: grunt is not defined"

转载 作者:IT老高 更新时间:2023-10-28 22:09:38 26 4
gpt4 key购买 nike

我是 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 上运行它。

如果您有任何想法,请告诉我。非常感谢大家!

最佳答案

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

关于node.js - Grunt 无法启动 : ">> ReferenceError: grunt is not defined",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/20247147/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com