Search code examples
javascriptgruntjsgrunt-contrib-uglify

GruntJS: Cannot call method filter of undefined


I'm new to grunt and tried installing it on a simple project. It worked but when I try to run 'ugilfy' my files I keep getting this error:

cannot call method   'filter' of undefined'

This is my grunt file (Gruntfile.js), saved in the root of my project:

module.exports = function(grunt)


{

grunt.initConfig({

    uglify: 
    { 
        options: 
        {
            mangle: true, 
            compress:true, 
            sourceMap: "dist/app.map", 
            banner: "/*  2014 */" 
        },

        //set of files where the plugin works on, (files which we can affect with our plugins like uglify)
        // culd be dev or production 
        target: 
        {

            //folder name equal to the JS object!!!
            js: "js/app.js", 
            dest: "dist/app.min.js"
        }
    }

});



//load plug-ins
grunt.loadNpmTasks('grunt-contrib-uglify'); 


};

I seriously have no idea why it is not working. I tried searching on google but I couldn't find any answers.


Solution

  • uglify.target is missing a src property.

    Change

    js: "js/app.js",
    

    to

    src: "js/app.js",
    

    and it should work properly.

    More on specifying sources and destinations are in the Grunt docs.