Gruntfile.js 警告:"path" 参数必须是字符串类型。接收类型对象使用--force继续

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

我在 运行 宁 g运行t 复制任务时遇到问题。我在 package.json 下的依赖项下指定了一个库

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

并在 Gruntfile.js 中声明复制任务如下

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']);

};

运行单独执行任务 "copy:autoCompleteJS" 或 "copy:autoCompleteCSS" 后,我收到以下警告

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.

注意:如果我 运行 任务 "copy:dist" 它工作正常。我怀疑在其他两个中提供给 cwd 的路径在目录名称中有特殊字符“@”导致了问题。

感谢您的帮助。

MSRS.

您的 copy 任务中 autoCompleteJSautoCompleteCSS 目标的 dest 值应该是字符串而不是数组。

//...
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
}
//...

此外,虽然并非完全有必要避免错误,但请考虑将两个目标的 src 值也更改为字符串而不是数组。