gruntjsgrunt-contrib-copygruntfile

Gruntfile.js Warning: The "path" argument must be of type string. Received type object Use --force to continue


I'm having an issue with running a grunt copy task. I've a library specified in package.json under dependencies as below

"@tarekraafat/autocomplete.js": "^7.2.0"

and declared copy tasks in Gruntfile.js as below

var paths = {
    webroot: "wwwroot/"
};

// destination css path
paths.cssOutput = paths.webroot + "css";

// where to find bower resources
paths.bower_components = paths.webroot + "lib";

// where to find reset.css
paths.resetCss = paths.bower_components + "/html5-reset/assets/css";

module.exports = function (grunt) {
    "use strict";

    // Project configuration
    grunt.initConfig({
        pkg: grunt.file.readJSON("package.json"),

        clean: [paths.cssOutput, paths.bower_components],

        // copy other css files
        copy: {
            options: {
                '-W069': false,
                'reporterOutput': "",
                'esnext': true
            },
            dist: {
                expand: true, // required when using cwd
                cwd: paths.resetCss, // set working folder / root to copy
                src: ['reset.css'], // copy all files and subfolders
                dest: paths.cssOutput //'./wwwroot/css/' // destination folder
            },
            autoCompleteJS: {
                expand: true,
                cwd: "wwwroot/lib/@tarekraafat/autocomplete.js/dist/js",
                src: ['autoComplete.min.js'],
                dest: ['wwwroot/js']
            },
            autoCompleteCSS: {
                expand: true,
                cwd: "wwwroot/lib/@tarekraafat/autocomplete.js/dist/css",
                src: ['autoComplete.css'],
                dest: ['wwwroot/css']
            }
        }
    });


    // Load the plugin
    grunt.loadNpmTasks('grunt-sass');
    grunt.loadNpmTasks('grunt-contrib-clean');
    grunt.loadNpmTasks('grunt-contrib-copy');

    grunt.registerTask('downloadPkgs', ['pkg']);
    grunt.registerTask('cleanAll', ['clean']);
    grunt.registerTask('copyAll', ['copy']);

};

Upon running the task "copy:autoCompleteJS" or "copy:autoCompleteCSS" individually, I'm getting the following warning

Running tasks: copy:autoCompleteCSS
Running "copy:autoCompleteCSS" (copy) task
Verifying property copy.autoCompleteCSS exists in config...OK
Warning: The "path" argument must be of type string. Received type object Use --force to continue.
Aborted due to warnings.
Process terminated with code 3.

Note: If I run the task "copy:dist" it is working fine. I suspect that the path supplied to cwd in the other two has special character "@" in the directory name is causing the issue.

Appreciated your help.

MSRS.


Solution

  • The dest value for both the autoCompleteJS and autoCompleteCSS Targets in your copy Task should be a String and not an Array.

    //...
    autoCompleteJS: {
        expand: true,
        cwd: "wwwroot/lib/@tarekraafat/autocomplete.js/dist/js",
        src: ['autoComplete.min.js'],
        dest: 'wwwroot/js'             // <----- Change to this
    },
    autoCompleteCSS: {
        expand: true,
        cwd: "wwwroot/lib/@tarekraafat/autocomplete.js/dist/css",
        src: ['autoComplete.css'],
        dest: 'wwwroot/css'            // <----- Change to this
    }
    //...
    

    Also, although not entirely necessary to avoid the error, consider changing the src value for both Targets to Strings instead of an Array too.