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

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

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

    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("src/css"))
        .pipe(browserSync.stream());
});

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

gulp.task('default', gulp.parallel('watch', 'server', 'styles'));




Выдаёт ошибку:

Professional@User-PC MINGW64 ~/Desktop/uber_course
$ gulp
Error [ERR_REQUIRE_ESM]: require() of ES Module C:\Users\Professional\Desktop\uber_course\node_modules\gulp-autoprefixer\index.js from C:\Users\Professional\Desktop\uber_c
ourse\gulpfile.js not supported.
Instead change the require of index.js in C:\Users\Professional\Desktop\uber_course\gulpfile.js to a dynamic import() which is available in all CommonJS modules.
at Object.<anonymous> (C:\Users\Professional\Desktop\uber_course\gulpfile.js:6:22) {
code: 'ERR_REQUIRE_ESM'
}




Что это значит ?


student_N5vzR7KI
1 year ago






До сих пор не могу понять в чём проблема ошибки !

student_N5vzR7KI
1 year ago

Наконец я решил эту проблему самостоятельно !!!

В  package.json  добавил строку  "type": "module",


В  gulpfile.js  заменил на это 

import gulp from 'gulp';
import browserSync from 'browser-sync';
import * as dartSass from 'sass';
import gulpSass from 'gulp-sass';
const sass = gulpSass(dartSass);
import cleanCSS from 'gulp-clean-css';
import autoprefixer from 'gulp-autoprefixer';
import rename from 'gulp-rename';



Вот результат !

Professional@User-PC MINGW64 ~/Desktop/uber_course (main)
$ gulp
[20:41:58] Using gulpfile ~\Desktop\uber_course\gulpfile.js
[20:41:58] Starting 'default'...
[20:41:58] Starting 'watch'...
[20:41:58] Starting 'server'...
[20:41:58] Starting 'styles'...
[Browsersync] 1 file changed (style.min.css)
[20:41:59] Finished 'styles' after 297 ms
[Browsersync] Access URLs:
 ---------------------------------------
       Local: http://localhost:3000
    External: http://192.168.43.250:3000
 ---------------------------------------
          UI: http://localhost:3001
 UI External: http://localhost:3001
 ---------------------------------------
[Browsersync] Serving files from: src














student_N5vzR7KI
1 year ago

2 ответов