sindresorhus / gulp-imagemin

Minify PNG, JPEG, GIF and SVG images
MIT License
1.9k stars 157 forks source link

Conflict with Gulp Load Plugins #361

Closed DaveyJake closed 2 years ago

DaveyJake commented 3 years ago

The following error message occurs when attempting to load the plugin using gulp-load-plugins:

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module: /path/to/node_modules/gulp-imagemin/index.js require() of ES modules is not supported. require() of /path/to/node_modules/gulp-imagemin/index.js from /path/to/node_modules/gulp-load-plugins/index.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 /path/to/node_modules/gulp-imagemin/index.js to end in .cjs, change the requiring code to use import(), or remove "type": "module" from /path/to/node_modules/gulp-imagemin/package.json.

I tried making the basic adjustments as suggested but none worked. Any ideas would be much appreciated.

Cheers 🍻

bobbyg603 commented 3 years ago

Try the following:

  1. npm i esm
  2. rename gulpfile.js to gulpfile.esm.js
  3. Update all your requires to imports
  4. gulp
strarsis commented 2 years ago

@bobbyg603: Thanks! However, it doesn't change anything, the error persists. 😞

bobbyg603 commented 2 years ago

@strarsis i ended up using gulp/typescript to solve this problem and forgot to update my answer, sorry about that! here's a link in the gulp docs that specifies how to use typescript https://gulpjs.com/docs/en/getting-started/javascript-and-gulpfiles/#transpilation

sindresorhus commented 2 years ago

https://gist.github.com/sindresorhus/a39789f98801d908bbc7ff3ecc99d99c