Gulp4迁移-无效的Glob参数

时间:2019-09-17 18:11:01

标签: javascript gulp

我正在研究从3.9.0版到gulp 4.0.0版的gulp迁移。

我在gulp.src('')上的gulpfile.js中遇到错误,错误消息是“错误:无效的全局参数:”

我在gulpfile.js中的gulp.task()看起来像这样-

gulp.task('build-version', function(done) {
    var dir = path.build + '/js',
        filename = "build.js";

    gulp.src('')
        .pipe(ngConfig('ppm', {
            createModule: false,
            constants: {
                newUIBuildVersion: buildVersion
            }
        }))
        .pipe(rename(filename))
        .pipe(gulp.dest(dir));

    // lint build.js file
    return gulp.src(dir + '/' + filename)
        .pipe(jshint(config.jshint))
        .pipe(jshint.reporter(stylish))
        .pipe(jshint.reporter('fail'))
        .on('error', function(err) {
            log(err);
        });});

和gulp版本:4.0.0,节点版本:8.11.4

我的错误消息:enter image description here

请在终端中找到错误消息的图像。

有人知道如何解决此问题吗?

1 个答案:

答案 0 :(得分:5)

我偶然发现了这个问题,并通过研究对该问题进行了发现,因为似乎并不能完全解决问题。

是的,该问题源于C:\>tracert 192.168.68.146 Tracing route to 192.168.68.146 over a maximum of 30 hops 1 <1 ms <1 ms <1 ms 10.63.10.1 2 <1 ms <1 ms <1 ms 172.16.63.2 为空,但是在Gulp 3中这是可以的,并且默认情况下允许。

根据Gulp文档(不是从迁移的角度出发,是为4.0编写的,它是真实的来源),看来您可以传入选项 gulp.src(''),默认情况下该选项为false。因此,如果您的代码为allowEmpty,则还需要指定gulp.src('')选项。

他们为上下文提供的示例是allowEmpty

下面是一个示例:src(globs, [options])

如果这行不通,我读过的其他文章说:gulp.src('', {allowEmpty: true})或:gulp.src([], {allowEmpty: true})

如果遇到其他问题,这里是所有选项的链接。

https://gulpjs.com/docs/en/api/src#errors

希望这会有所帮助!谢谢!