Gruntfile.js警告:“ path”参数必须为字符串类型。收到的类型对象使用--force继续

时间:2019-12-30 14:36:48

标签: gruntjs grunt-contrib-copy gruntfile

我在运行grunt复制任务时遇到问题。我在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”时,出现以下警告

  

运行任务:copy:autoCompleteCSS
  运行“ copy:autoCompleteCSS”(复制)任务
  验证属性copy.autoCompleteCSS是否存在于配置中...确定
  警告:“路径”参数必须为字符串类型。收到的类型对象使用--force继续。
  由于警告而中止。
  进程以代码3终止。

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

感谢您的帮助。

MSRS。

1 个答案:

答案 0 :(得分:1)

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

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

尽管并非完全必要以避免错误,但也可以考虑将两个Target的src值都更改为String而不是Array。