I’m having a trouble with gulp-imagemin. When I test the minify-image task, it can’t run. I tried a lot of ways to fix it but every time it had a problem. Can someone help me to fix this? I need this very much.
how I import gulp & gulp-imagemin:
const gulp = require('gulp');
const imagemin = require('gulp-imagemin');
how I write the task:
// gulp.task('minifyimage', () =>
// gulp.src('src/assets/img/*')
// .pipe(imagemin())
// .pipe(gulp.dest('dist/assets/img/'))
// );
gulp.task('minifyimage', async function () {
return gulp
.src('src/assets/img/*')
.pipe(imagemin())
.pipe(gulp.dest('dist/assets/img/'));
});
// export default () => (
// gulp.src('src/images/*')
// .pipe(imagemin())
// .pipe(gulp.dest('dist/images'))
// );
// function imgSquash() {
// return gulp
// .src('src/assets/img/*')
// .pipe(imagemin())
// .pipe(gulp.dest('dist/assets/img/'));
// }
fix this problem. just fix this problem.
here is the problem:
PS C:UsersMatinDownloadsgulpApp> gulp optimize-images
[03:48:08] Loaded external module: C:UsersMatinAppDataRoamingnpmnode_modulesgulpnode_modulesinterpretcjs-stub
(node:23416) ExperimentalWarning: CommonJS module C:UsersMatinDownloadsgulpAppgulpfile.cjs is loading ES Module C:UsersMatinDownloadsgulpAppnode_modulesgulp-imageminindex.js using require().
Support for loading ES Module in require() is an experimental feature and might change at any time
(Use node --trace-warnings ...
to show where the warning was created)
Error: require() cannot be used on an ESM graph with top-level await. Use import() instead. To see where the top-level await comes from, use –experimental-print-required-tla.