Javascript Grunt.js:加载任务导致TypeError:对象不是函数
我试图执行grunt watch任务,但grunt抛出错误:Javascript Grunt.js:加载任务导致TypeError:对象不是函数,javascript,node.js,coffeescript,gruntjs,Javascript,Node.js,Coffeescript,Gruntjs,我试图执行grunt watch任务,但grunt抛出错误: TypeError: object is not a function 我的咖啡脚本编译任务失败: coffee: compile: files: 'path/to/result.js': 'path/to/source.coffee' 这真的很基本,所以我看不出哪里出了问题。知道会发生什么吗 下面是运行grunt watch-v后生成的堆栈跟踪: agconti :: ~/dev/my_pro
TypeError: object is not a function
我的咖啡脚本编译任务失败:
coffee:
compile:
files: 'path/to/result.js': 'path/to/source.coffee'
这真的很基本,所以我看不出哪里出了问题。知道会发生什么吗
下面是运行grunt watch-v
后生成的堆栈跟踪:
agconti :: ~/dev/my_project ‹master*› » grunt watch -v 3 ↵
Initializing
Command-line options: --verbose
Reading "Gruntfile.coffee" Gruntfile...OK
Registering Gruntfile tasks.
Reading package.json...OK
Parsing package.json...OK
Loading "Gruntfile.coffee" tasks...ERROR
>> TypeError: object is not a function
>> at Object.module.exports (/Users/admin/dev/fueled-boilerplate/Gruntfile.coffee:58:88)
>> at loadTask (/Users/admin/dev/fueled-boilerplate/node_modules/grunt/lib/grunt/task.js:318:10)
>> at Task.task.init (/Users/admin/dev/fueled-boilerplate/node_modules/grunt/lib/grunt/task.js:430:5)
>> at Object.grunt.tasks (/Users/admin/dev/fueled-boilerplate/node_modules/grunt/lib/grunt.js:113:8)
>> at Object.module.exports [as cli] (/Users/admin/dev/fueled-boilerplate/node_modules/grunt/lib/grunt/cli.js:38:9)
>> at Object.<anonymous> (/usr/local/lib/node_modules/grunt-cli/bin/grunt:43:20)
>> at Module._compile (module.js:456:26)
>> at Object.Module._extensions..js (module.js:474:10)
>> at Module.load (module.js:356:32)
>> at Function.Module._load (module.js:312:12)
加载grunt任务文件:
'use strict';
var globule = require('globule');
var findup = require('findup-sync');
var path = require('path');
function arrayify(el) {
return Array.isArray(el) ? el : [el];
}
module.exports = function (grunt, options) {
options = options || {};
var pattern = arrayify(options.pattern || ['grunt-*']);
var config = options.config || findup('package.json');
var scope = arrayify(options.scope || ['dependencies', 'devDependencies', 'peerDependencies']);
if (typeof config === 'string') {
config = require(path.resolve(config));
}
pattern.push('!grunt', '!grunt-cli');
var names = scope.reduce(function (result, prop) {
return result.concat(Object.keys(config[prop] || {}));
}, []);
globule.match(pattern, names).forEach(grunt.loadNpmTasks);
};
package.json:
{
"name": "fueled-boilerplate",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-sass": "~0.6.0",
"grunt-contrib-imagemin": "~0.4.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-connect": "~0.5.0",
"grunt-autoprefixer": "~0.5.0",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-compass": "~0.7.0",
"grunt-modernizr": "~0.4.1",
"grunt-contrib-coffee": "~0.8.0"
},
"dependencies": {
"load-grunt-tasks": "~0.2.0"
}
}
尝试干净地安装npm模块:
rm-rf节点\u模块和&npm缓存清理和&npm安装
我遇到了同样的问题,并通过替换代码标识中的制表符空格(下面的点)解决了这个问题
我们可以查看您的
加载grunt任务
文件吗?显示上面包含的包.json
@IlanFrumer@dcodesmithabove@IlanFrumer那是一个很好的包裹。谢谢你的写作!好主意,不过问题是一样的。
{
"name": "fueled-boilerplate",
"version": "0.1.0",
"devDependencies": {
"grunt": "~0.4.1",
"grunt-contrib-concat": "~0.3.0",
"grunt-contrib-uglify": "~0.2.7",
"grunt-contrib-sass": "~0.6.0",
"grunt-contrib-imagemin": "~0.4.0",
"grunt-contrib-watch": "~0.5.3",
"grunt-contrib-connect": "~0.5.0",
"grunt-autoprefixer": "~0.5.0",
"grunt-contrib-cssmin": "~0.7.0",
"grunt-contrib-jshint": "~0.7.2",
"grunt-contrib-clean": "~0.5.0",
"grunt-contrib-compass": "~0.7.0",
"grunt-modernizr": "~0.4.1",
"grunt-contrib-coffee": "~0.8.0"
},
"dependencies": {
"load-grunt-tasks": "~0.2.0"
}
}
coffee:
....compile:
........files: 'path/to/result.js': 'path/to/source.coffee'