0
0

При запуске данного кода(через команду gulp):

const gulp = require('gulp');
const browserSync = require('browser-sync');
const sass = require('gulp-sass')(require('sass'));
const rename = require('gulp-rename');
const autoprefixer = require('gulp-autoprefixer');
const cleanCSS = require('gulp-clean-css');
const imagemin = require('gulp-imagemin');
const htmlmin = require('gulp-htmlmin');

gulp.task('server', function() {

    browserSync({
        server: {
            baseDir: "dist"
        }
    });

    gulp.watch("src/*.html").on('change', browserSync.reload);
});

gulp.task('styles', function() {
    return gulp.src("src/sass/**/*.+(scss|sass)")
        .pipe(sass({outputStyle: 'compressed'}).on('error', sass.logError))
        .pipe(rename({suffix: '.min', prefix: ''}))
        .pipe(autoprefixer())
        .pipe(cleanCSS({compatibility: 'ie8'}))
        .pipe(gulp.dest("dist/css"))
        .pipe(browserSync.stream());
});

gulp.task('watch', function() {
    gulp.watch("src/sass/**/*.+(scss|sass|css)", gulp.parallel('styles'));
    gulp.watch("src/*.html").on('change', gulp.parallel('html'));
});

gulp.task('html', function () {
    return gulp.src("src/*.html)")
        .pipe(htmlmin({ collapseWhitespace: true }))
        .pipe(gulp.dest("dist/"))
});

gulp.task('scripts', function () {
    return gulp.src("src/js/**/*.js)")
        .pipe(gulp.dest("dist/js"))
});

gulp.task('fonts', function () {
    return gulp.src("src/fonts/**/*)")
        .pipe(gulp.dest("dist/icons"))
});

gulp.task('icons', function () {
    return gulp.src("src/icons/**/*)")
        .pipe(gulp.dest("dist/js"))
});

gulp.task('mailer', function () {
    return gulp.src("src/mailer/**/*)")
        .pipe(gulp.dest("dist/mailer"))
});

gulp.task('images', function () {
    return gulp.src("src/img/**/*)")
        .pipe(imagemin())
        .pipe(gulp.dest("dist/img"))
});

gulp.task('default', gulp.parallel('watch', 'server', 'styles', 'scripts', 'fonts', 'icons', 'mailer', 'html', 'images'));


Приходит так же в терминал следующее:

Error [ERR_REQUIRE_ESM]: require() of ES Module D:\IT\WEB\Project\RunSmart\node_modules\gulp-imagemin\index.js from D:\IT\WEB\Project\RunSmart\gulpfile.js not supported.   
Instead change the require of index.js in D:\IT\WEB\Project\RunSmart\gulpfile.js to a dynamic import() which is available in all CommonJS modules.
    at Object.<anonymous> (D:\IT\WEB\Project\RunSmart\gulpfile.js:7:18)
    at async Promise.all (index 0) {
  code: 'ERR_REQUIRE_ESM'
}


Помогите я не знаю как решить проблему и уже 3 дня не могу продолжить учиться


Oleh Khmilovskyi
1 year ago






Добрый день. Тут есть несколько вариантов:

1) Установить немного другую версию пакета gulp-imagemin. Для этого запустите в терминале, в проекте команду:

npm i gulp-imagemin@7.1.0

Она должна работать без ошибки

2) Или убрать все упоминания этого пакета из gulpfile. При желании найти потом альтернативу. Убираем строки:

const imagemin = require('gulp-imagemin');

и

.pipe(imagemin())

Иван Петриченко
1 year ago

Один ответ