سلام
استاد ببخشید ، زمانی که imagemin رو اجرا میکنم ، این ارور میده
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: C:\Users\sepid\Desktop\New folder\gulpApp\node_modules\gulp-imagemin\index.js
require() of ES modules is not supported.
require() of C:\Users\sepid\Desktop\New folder\gulpApp\node_modules\gulp-imagemin\index.js from C:\Users\sepid\Desktop\New folder\gulpApp\gulpfile.js is an ES module file as it is a .js file whose nearest parent package.json contains "type": "module" which defines all .js files in that package scope as ES modules.
Instead rename index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from C:\Users\sepid\Desktop\New folder\gulpApp\node_modules\gulp-imagemin\package.json.
at new NodeError (node:internal/errors:363:5)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1112:13)
at Module.load (node:internal/modules/cjs/loader:975:32)
at Function.Module._load (node:internal/modules/cjs/loader:816:12)
at Module.require (node:internal/modules/cjs/loader:999:19)
at require (node:internal/modules/cjs/helpers:93:18)
at Object.<anonymous> (C:\Users\sepid\Desktop\New folder\gulpApp\gulpfile.js:1:18)
at Module._compile (node:internal/modules/cjs/loader:1095:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1124:10)
at Module.load (node:internal/modules/cjs/loader:975:32) {
code: 'ERR_REQUIRE_ESM'
این هم کدش مربوطه هستش
const imagemin = require('gulp-imagemin');
const gulp = require('gulp');
// My task
// console.log
gulp.task('msg' , async function() {
console.log(' This my first task With Gulp !!!')
})
// Copy HTML files to dist folder
gulp.task('copyHtml' , async function() {
gulp.src('src/*.html')
.pipe(gulp.dest('dist'))
await console.log( "done ");
})
// Minify image
gulp.task('minIamge' , async function() {
gulp.src('src/assets/img/*.*')
.pipe(imagemin())
.pipe(gulp.dest('dist/assets/img'))
})
چیکارش کنم ؟