javascript 加载“Gruntfile.js”任务......运行`grunt`时出错
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/30171593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Loading "Gruntfile.js" tasks...ERROR while running `grunt`
提问by cyber8200
I'm new to the Grunt world.
我是 Grunt 世界的新手。
After installing grunt-cli, and all the dependencies, here is my : Gruntfile.js
安装 grunt-cli 和所有依赖项后,这是我的: Gruntfile.js
/*
Grunt installation:
-------------------
npm install -g grunt-cli
npm install -g grunt-init
npm init (creates a `package.json` file)
Project Dependencies:
---------------------
npm install grunt --save-dev
npm install grunt-contrib-concat --save-dev
npm install grunt-contrib-watch --save-dev
Example Usage:
--------------
grunt -v
grunt release -v
*/
module.exports = function(grunt) {
"use strict";
grunt.initConfig({
concat: {
js: {
src: ['js/bootstrap.min.js', 'js/jquery-1.10.2.min.js'],
dest: 'build/js/scripts.js'
},
css: {
src: ['css/bootstrap.min.css', 'css/font-awesome.min.css'],
dest: 'build/css/styles.css'
}
},
watch: {
js: {
files: ['js/**/*.js'],
task: ['concat:js']
},
css: {
files: ['css/**/*.css'],
task: ['concat:css']
}
}
});
grunt.loadNpmTasks('grunt-contrib-concat');
grunt.loadNpmTasksNpmTasks('grunt-contrib-watch');
grunt.registerTask('default', ['concat', 'watch']);
};
Result
结果
Now the testing part, I tried run grunt
, I kept getting :
现在是测试部分,我尝试了 run grunt
,我不断得到:
Loading "Gruntfile.js" tasks...ERROR
>> TypeError: undefined is not a function
Warning: Task "default" not found. Use --force to continue.
Aborted due to warnings.
Can someone please tell me what did I do wrong here ?
有人可以告诉我我在这里做错了什么吗?
回答by Daniel Imms
It looks like the default
target is not being created properly due to a typo. Try renaming
default
由于打字错误,目标似乎没有被正确创建。尝试重命名
grunt.loadNpmTasksNpmTasks('grunt-contrib-watch');
to
到
grunt.loadNpmTasks('grunt-contrib-watch');
回答by AdroitSJ
Have faced similar issues and tried below command where your node modules is installed which resolved issue for me:
遇到过类似的问题,并在安装节点模块的地方尝试了以下命令,这为我解决了问题:
npm install --unsafe-perm