Greg Bailey
Greg Bailey

Reputation: 79

Grunt contrib-clean with files object error 'Object #<Object> has no method of 'indexOf' Use --force to continue

I am using grunt contrib-clean to remove minified js files and want to specify the files by specifying the files object dynamically. When I do, I get the error: 'Object # has no method of 'indexOf' Use --force to continue.'

Here are my options I am specifying.

clean: {
        files: [{
            expand: true,
            cwd: 'js/',
            src: ['**/*.min.js', '!**/data/**', '!**/vendor/**', '!**/jquery/**', '!**/knockout/**'],
        }]
},

This pattern, without specifying the files object works, but I'm curious as to why the code above fails.

    clean: {
        src: ['js/**/*.min.js', '!js/**/data/**', '!js/**/vendor/**', '!js/**/jquery/**', '!js/**/knockout/**'],
    },

I arrived at this problem when trying to use cwd for file operations because I have grunt installed in a sub-directory and was always trying to cwd to the root to perform operations, then I discovered grunt.file.setBase('../').

Any help would be appreciated.

-greg

Upvotes: 1

Views: 2174

Answers (1)

Kyle Robinson Young
Kyle Robinson Young

Reputation: 13762

In your first example, you're missing a target name, which are required for multi tasks.

Where your second example, your target name is src.

Just add a target name and the first example should work (although since you've only got a single object within the files array configure, it's unnecessary):

clean: {
  target: {
    files: [{
        expand: true,
        cwd: 'js/',
        src: ['**/*.min.js', '!**/data/**', '!**/vendor/**', '!**/jquery/**', '!**/knockout/**'],
    }]
  }
},

Upvotes: 4

Related Questions