Trying to start server with Gulp and it throw error

571 Views Asked by At

I'm trying to run sever and I get this assertion error. I've uninstalled node and NPM and reinstalled again also I tried many steps and suggested solutions here but it doesn't fit with my problem.

AssertionError [ERR_ASSERTION]: Task never defined: node_modules/scss/bootstrap.scss
        at getFunction (C:\Users\Saviour\Desktop\Portfolio\Bootstrap\Project1\node_modules\undertaker\lib\helpers\normalizeArgs.js:15:5)
        at map (C:\Users\Saviour\Desktop\Portfolio\Bootstrap\Project1\node_modules\arr-map\index.js:20:14)
        at normalizeArgs (C:\Users\Saviour\Desktop\Portfolio\Bootstrap\Project1\node_modules\undertaker\lib\helpers\normalizeArgs.js:22:10)
        at Gulp.series (C:\Users\Saviour\Desktop\Portfolio\Bootstrap\Project1\node_modules\undertaker\lib\series.js:13:14)
        at C:\Users\Saviour\Desktop\Portfolio\Bootstrap\Project1\gulpfile.js:7:26
        at sass (C:\Users\Saviour\Desktop\Portfolio\Bootstrap\Project1\node_modules\undertaker\lib\set-task.js:13:15)
        at bound (domain.js:422:14)
        at runBound (domain.js:435:12)
        at asyncRunner (C:\Users\Saviour\Desktop\Portfolio\Bootstrap\Project1\node_modules\async-done\index.js:55:18)
        at processTicksAndRejections (internal/process/task_queues.js:75:11)

This's my code

var gulp = require('gulp');
var browserSync = require('browser-sync').create();
var sass = require('gulp-sass');


gulp.task('sass', async function () {
    return gulp.src(gulp.series('node_modules/scss/bootstrap.scss', 'src/scss/*.scss'))
        .pipe(sass())
        .pipe(gulp.dest("src/css"))
        .pipe(browserSync.stream());
});


gulp.task('js', async function () {
    return gulp.src(gulp.series('node_modules/bootstrap/dist/js/bootstrap.min.js', 'node_modules/jquery/dist/jquery.min.js', 'node_modules/popper.js/dist/popper.min.js'))
        .pipe(gulp.dest('src/js'))
        .pipe(browserSync.stream());
});


gulp.task('serve', async function () {
    browserSync.init({
        server: "./src",
    });
    gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], 'sass');
    gulp.watch("src/*.html").on('change', browserSync.reload);
})


gulp.task('default', gulp.series(gulp.parallel('sass', 'js', 'serve')));
1

There are 1 best solutions below

1
On

The error is coming from the sass and js tasks. You are wrapping your sources in gulp.series. So Gulp is trying to run your sources as tasks.

They just need to be in an array [] like in the watch task.

Just change:

gulp.task('sass', async function () { return gulp.src(gulp.series('node_modules/scss/bootstrap.scss', 'src/scss/*.scss'))

to:

gulp.task('sass', async function () { return gulp.src(['node_modules/scss/bootstrap.scss', 'src/scss/*.scss'])

and then the same format in the js task


The second error (coming from your watch task) is because you need to wrap the tasks you are watching in either series or parallel. Even when theres only one task So change:

gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], 'sass');

to:

gulp.watch(['node_modules/bootstrap/scss/bootstrap.scss', 'src/scss/*.scss'], gulp.series('sass'));