Answer the question
In order to leave comments, you need to log in
TypeError: imagemin is not a function how to fix in gulpfile?
Default gulp command not running.
Here is my gulpfile.js :
const {
src,
dest,
parallel,
series,
watch
} = require('gulp');
// Load plugins
const cssnano = require('gulp-cssnano');
const changed = require('gulp-changed');
const browsersync = require('browser-sync').create();
const imagemin = import('gulp-imagemin');
const clean = require('gulp-clean');
function clear() {
return src('./build/*', {
read: false
})
.pipe(clean());
}
// CSS
function css() {
const source = './src/css/style.css';
return src(source)
.pipe(changed(source))
.pipe(cssnano())
.pipe(dest('./build/css/'))
.pipe(browsersync.stream());
}
// Optimize images
function img() {
return src('./src/images/*')
.pipe(imagemin())
.pipe(dest('./build/imeges'));
}
// html
function html() {
return src('./src/*.html')
.pipe(dest('./build/'))
.pipe(browsersync.stream())
}
// Watch files
function watchFiles() {
watch('./src/css/*', css);
watch('./src/*.html', html);
watch('./src/images/*', img);
}
// BrowserSync
function browserSync() {
browsersync.init({
server: {
baseDir: './build'
},
port: 3000
});
}
exports.watch = parallel(watchFiles, browserSync);
exports.default = series(clear, parallel(html, css, img));
[09:36:44] Using gulpfile ~\Desktop\app\gulpfile.js
[09:36:44] Starting 'default'...
[09:36:44] Starting 'clear'...
[09:36 :44] Finished 'clear' after 45 ms
[09:36:44] Starting 'html'...
[09:36:44] Starting 'css'...
[09:36:44] Starting 'img'. ..
[09:36:44] 'img' errored after 12 ms
[09:36:44] TypeError: imagemin is not a function
at img (C:\Users\Samrux\Desktop\app\gulpfile.js:42: 15)
at bound (node:domain:421:15)
at runBound (node:domain:432:12)
at asyncRunner (C:\Users\Samrux\Desktop\app\node_modules\async-done\index.js:55: 18)
at processTicksAndRejections (node:internal/process/task_queues:78:11)
[09:36:44] 'default' errored after 72 ms
'ERR_REQUIRE_ESM'
"browser-sync": "^2.27.5",
"gulp": "^4.0.2",
"gulp-changed": "^4.0.3",
"gulp-clean": "^0.4.0",
"gulp-cssnano": "^2.1.3",
"gulp-imagemin": "^8.0.0"
Answer the question
In order to leave comments, you need to log in
change import to require
UPD
AND downgrade gulp-imagemin to 7.1.0
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question