javascript - 咕噜.js : Loading task causes TypeError: object is not a function

标签 javascript node.js coffeescript gruntjs

我正在尝试执行我的 grunt 监视任务,但 grunt 抛出错误:

TypeError: object is not a function

我的 CoffeeScript 编译任务失败了:

 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)

这是整个 Gruntfile.coffee:

module.exports = (grunt) ->

# Project configuration.
    grunt.initConfig
        pkg: grunt.file.readJSON 'package.json'

# CSS processing
        sass: 
            dist: 
                options: 
                    style: 'expanded'
                files: 
                    'assets/build/css/compiled/screen.css' : 'assets/css/screen.scss'

        compass: 
            options: 
                sassDir: 'assets/css/'
                cssDir: 'assets/build/css/compiled/'
                imagesDir: 'assets/images/'
                javascriptsDir: 'assets/build/js/'
                outputStyle: 'expanded'

            dist:""
            server: 
                options: 
                    debugInfo: true

        autoprefixer: 
            options: 
                browsers: ['last 2 version']

            multiple_files:
                expand: true,
                flatten: true,
                src: 'assets/build/css/compiled/screen.css'
                dest: 'assets/build/css/prefixed/'

        modernizr: 
            "devFile": "assets/js/modernizr/modernizr-2.6.2.min.js"
            "outputFile": "assets/build/js/modernizr-custom.js"

        cssmin: 
            combine: 
                files:'assets/build/css/screen.min.css': ['assets/build/css/prefixed/screen.css']

# JavaScript Processing
        coffee: 
            compile: 
                files: 'path/to/result.js': 'path/to/source.coffee' 

        jshint: 
            beforeconcat: ['assets/js/*.js']

        concat: 
            dist: 
                src: [
                    'assets/js/vendor/*.js'
                    'assets/js/*.js']
                dest: 'assets/build/js/main.js'

        uglify: 
            build: 
                src: 'assets/build/js/main.js',
                dest: 'assets/build/main.min.js'

# Image Processing
        imagemin: 
            dynamic: 
                files: [
                    expand: true
                    cwd: "assets/images/"
                    src: ['**/*.{png,gif,jpg}']
                    dest: "assets/images/"
                    ]

# Watch Task
        watch: 
            options:
                livereload: 
                    port: 9000 # Allows you to specify port incase you want to run multiple projects as once.
                    #Allows you to connect an Https server and still have livereload 
                    key: grunt.file.read 'path/to/ssl.key'
                    cert: grunt.file.read 'path/to/ssl.crt'
                    #you can pass in any other options you'd like to the https server, as listed here: http://nodejs.org/api/tls.html#tls_tls_createserver_options_secureconnectionlistener
            scripts: 
                files: 'assets/js/*/js'
                tasks: ['concat', 'uglify', 'jshint']
                options: 
                    spawn: false

            html: 
                files: ['*.html', '**/*.html']
                tasks: []
                options: 
                    spawn: false


            compass: 
                files: ['assets/css/*.scss', 'assets/css/**/*.scss']
                tasks: ['compass:server', 'autoprefixer', 'cssmin', 'clean']

            images: 
                files: ['assets/images/**/*.{png,gif,jpg}', 'assets/images/*.{png,gif,jpg}']
                tasks: ['imagemin']
                options: 
                    spawn: false

# Connect Task
        connect: 
            server: 
                options: 
                    port: 8000
                    base: './'

# Clean Task
        clean: ['assets/build/css/prefixed/', 'assets/build/css/compiled/']


# Load dependencies
    require('load-grunt-tasks')(grunt)

# Define Tasks
    grunt.registerTask 'default', [
                                    'concat' 
                                    'uglify' 
                                    'sass' 
                                    'imagemin'
                                ]

    grunt.registerTask 'dev', [
                                'connect' 
                                'modernizr' 
                                'watch'
                            ]

加载 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 node_modules && npm cache clean && npm install

关于javascript - 咕噜.js : Loading task causes TypeError: object is not a function,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21145637/

相关文章:

javascript - Vanilla Javascript 在窗口调整大小时操作元素

javascript - 语法错误 : Unexpected token * after importing sequelize model db object

javascript - 点击时更改 JWPlayer 视频

javascript - 为什么我的列表项调用了它不应该调用的函数?

javascript - 如何使用 git 备份我的项目?

node.js - 我的nodejs简单代码有什么问题

javascript - 为什么未处理的 promise 拒绝

java - 将 json 映射到 Java 对象

javascript - React 组件自动绑定(bind)

javascript - 输入后需要获取coffeescript的数据