0

我正在尝试运行服务器并收到此断言错误。我已经卸载了节点和 NPM 并再次重新安装,我在这里尝试了许多步骤和建议的解决方案,但它不适合我的问题。

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)

这是我的代码

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

1 回答 1

0

错误来自sassandjs任务。您将源代码包装在gulp.series. 所以 Gulp 正在尝试将您的源代码作为任务运行。

它们只需要[]像 watch 任务一样在一个数组中。

只是改变:

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

至:

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

然后在js任务中同样的格式


第二个错误(来自您的 watch 任务)是因为您需要将正在观看的任务包装在seriesparallel中。即使只有一项任务所以改变:

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

至:

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

于 2019-12-03T17:20:12.400 回答