Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

gulpfile error recived a non-Vinyl object

I'm trying to convert a old gulpjs file to es6 but i keep getting this error message in the concat task:

Error: Recived a non-Vinyl object in dest()

My gulpfile.js:

import gulp from 'gulp';

/*********** Jade and Pug templating ***********/
import jade from 'gulp-jade';
import pug from 'gulp-pug';

/*********** SASS and SCSS compiling ***********/
import sass from 'gulp-sass';
import autoprefixer from 'gulp-autoprefixer';
import cleanCss from 'gulp-clean-css';

/*********** JS concat and minify ***********/
import concat from 'gulp-concat';
import minify from 'gulp-minify';

/*********** Static server ***********/
import bs from 'browser-sync';

const dirs = {
    pug_src: 'views',
    sass_src: 'assets/scss',
    js_src: 'assets/js',
    dist: 'dist',
    js_dist: 'dist/js/',
    sass_dist: 'dist/css/'
};

const files = {
    pug: `${dirs.pug_src}/*.pug`,
    sass: `${dirs.sass_src}/*.sass`,
    js: `${dirs.js_src}/*.js`,
    html: `${dirs.dist}/*.html`
}

/*********** HTML ***********/
gulp.task('pug', () => {
    return gulp.src(files.pug)
    .pipe(pug({
        pretty: false
    }).on('error', (e) => {
        console.log(e)
    }))
    .pipe(gulp.dest(dirs.dist));
});

/*********** Styles ***********/
gulp.task('sass', () => {
    return gulp.src(files.sass)
    .pipe(sass({
        outputStyle: 'compressed'
    })
    .on('error', sass.logError))
    .pipe(gulp.dest(dirs.sass_dist))
    .pipe(autoprefixer({
        browsers: ['last 2 versions'],
        cascade: false
    }))
    .pipe(cleanCss({
        compatibility: 'ie8'
    }))
    .pipe(bs.stream());
});

/*********** Concat JS files ***********/
gulp.task('concat', () => {
    return gulp.src(files.js)
    .pipe(concat('main.js'))
    .pipe(minify({
        src: 'main.js',
        min: '.min.js'
    }))
    .pipe(gulp.dest(dirs.js_dist));
});

/*********** BrowserSync ***********/
gulp.task('serve', gulp.series('pug', 'sass', 'concat'), () => {
    bs.init({
        server: {
            baseDir: dirs.dist
        }
    });
});

/*********** Watch ***********/
gulp.task('watch', () => {
    gulp.watch(files.pug, gulp.series('pug'));
    gulp.watch(files.sass, gulp.series('sass'));
    gulp.watch(files.js, gulp.series('concat')).on('change', bs.reload);
    gulp.watch(files.html).on('change', bs.reload);
});

/*********** Default ***********/
gulp.task('default', gulp.series('serve', 'watch'));

i have changed the gulp.dist() from gulp.dest(dirs.js_dist) to gulp.dest('dist/js/') and still got the same error.

[16:30:20] Failed to load external module @babel/register
[16:30:20] Requiring external module babel-register
[16:30:38] Using gulpfile ~/Workspace/Projects/AHTM-source/gulpfile.babel.js
[16:30:38] Starting 'default'...
[16:30:38] Starting 'serve'...
[16:30:38] Starting 'pug'...
[16:30:38] Finished 'pug' after 415 ms
[16:30:38] Starting 'sass'...
[16:30:39] Finished 'sass' after 369 ms
[16:30:39] Starting 'concat'...
[16:30:39] 'concat' errored after 69 ms
[16:30:39] Error: Received a non-Vinyl object in `dest()`
    at DestroyableTransform.normalize [as _transform] (/home/cdetecnologias/Workspace/Projects/AHTM-source/node_modules/vinyl-fs/lib/dest/prepare.js:16:17)
    at DestroyableTransform.Transform._read (/home/cdetecnologias/Workspace/Projects/AHTM-source/node_modules/readable-stream/lib/_stream_transform.js:184:10)
    at DestroyableTransform.Transform._write (/home/cdetecnologias/Workspace/Projects/AHTM-source/node_modules/readable-stream/lib/_stream_transform.js:172:83)
    at doWrite (/home/cdetecnologias/Workspace/Projects/AHTM-source/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/home/cdetecnologias/Workspace/Projects/AHTM-source/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at DestroyableTransform.Writable.write (/home/cdetecnologias/Workspace/Projects/AHTM-source/node_modules/readable-stream/lib/_stream_writable.js:334:11)
    at Pumpify.Duplexify._write (/home/cdetecnologias/Workspace/Projects/AHTM-source/node_modules/duplexify/index.js:208:22)
    at doWrite (/home/cdetecnologias/Workspace/Projects/AHTM-source/node_modules/readable-stream/lib/_stream_writable.js:428:64)
    at writeOrBuffer (/home/cdetecnologias/Workspace/Projects/AHTM-source/node_modules/readable-stream/lib/_stream_writable.js:417:5)
    at Pumpify.Writable.write (/home/cdetecnologias/Workspace/Projects/AHTM-source/node_modules/readable-stream/lib/_stream_writable.js:334:11)
[16:30:39] 'serve' errored after 856 ms
[16:30:39] 'default' errored after 859 ms
like image 498
alejandrohtadinom Avatar asked Jul 03 '18 20:07

alejandrohtadinom


1 Answers

This looks like it's caused by a version change of Vinyl in the latest version of Gulp, as it is a breaking change:

https://github.com/gulpjs/gulp/commit/c1ba80cb6b1a2e1469a7f422ec6ee93ac589d714#diff-b9cfc7f2cdf78a7f4b91a753d10865a2

And specifically a package you depend on is importing an older version of Vinyl, most likely minify. Most likely this has been updated (The original question was asked in July 2018), but for others who are converting gulp scripts you may run into this.

The package dependency (GulpJS plugin) should use the latest version of Vinyl. See: https://gulpjs.com/docs/en/api/vinyl

like image 152
MrMowgli Avatar answered Oct 04 '22 13:10

MrMowgli