You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
I think This error can be resolved by version downgrading.
or
1 ) in your package.json
Add "type":"module"
2 ) Edit code
// const imagemin = require("imagemin");importimageminfrom"imagemin";// << edit this line importimageminMozjpegfrom"imagemin-mozjpeg";// << edit this line// const imageminMozjpeg = require("imagemin-mozjpeg");(async()=>{constfiles=awaitimagemin(["./img/*.{jpeg,jpg,png}"],{destination: "./output/",plugins: [imageminMozjpeg({quality: 80})],});console.log(files);//=> [{data: <Buffer 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …]})();thenitworks!!!☺️
Below is the problem situation.
library ver
[email protected]
added 42 packages from 32 contributors and audited 42 packages in 3.225s
[email protected]
added 253 packages from 75 contributors and audited 325 packages in 9.66s
project folder directory
constimagemin=require("imagemin");// <- error is shootingconstimageminMozjpeg=require("imagemin-mozjpeg");(async()=>{constfiles=awaitimagemin(["./img/*.{jpeg,jpg,png}"],{destination: "./output/",plugins: [imageminMozjpeg({quality: 80})],});console.log(files);//=> [{data: <Buffer 89 50 4e …>, destinationPath: 'build/images/foo.jpg'}, …]})();
error
internal/modules/cjs/loader.js:1080
throw new ERR_REQUIRE_ESM(filename, parentPath, packageJsonPath);
^
Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /Users/jangjunhyeog/Workspace/JavascriptPractice/IMAGE-OPTIMIZATION/node_modules/imagemin/index.js
require() of ES modules is not supported.
require() of /Users/jangjunhyeog/Workspace/JavascriptPractice/IMAGE-OPTIMIZATION/node_modules/imagemin/index.js from /Users/jangjunhyeog/Workspace/JavascriptPractice/IMAGE-OPTIMIZATION/script.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 /Users/jangjunhyeog/Workspace/JavascriptPractice/IMAGE-OPTIMIZATION/node_modules/imagemin/package.json.
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1080:13)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Module.require (internal/modules/cjs/loader.js:952:19)
at require (internal/modules/cjs/helpers.js:88:18)
at Object.<anonymous> (/Users/jangjunhyeog/Workspace/JavascriptPractice/IMAGE-OPTIMIZATION/script.js:1:18)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14) {
code: 'ERR_REQUIRE_ESM'
}
The text was updated successfully, but these errors were encountered:
I Solved It☺️ .
I think This error can be resolved by version downgrading.
or
1 ) in your package.json
Add "type":"module"
2 ) Edit code
Below is the problem situation.
[email protected]
added 42 packages from 32 contributors and audited 42 packages in 3.225s
[email protected]
added 253 packages from 75 contributors and audited 325 packages in 9.66s
The text was updated successfully, but these errors were encountered: