imagemin-svgo icon indicating copy to clipboard operation
imagemin-svgo copied to clipboard

Error [ERR_REQUIRE_ESM]: Must use import to load ES Module

Open JBaczuk opened this issue 3 years ago • 1 comments

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

This fixes a build error with next.js and the ERR_REQUIRE_ESM error.

https://github.com/vercel/next.js/issues/30307

Here is the diff that solved my problem:

diff --git a/node_modules/imagemin-svgo/index.js b/node_modules/imagemin-svgo/index.cjs
similarity index 100%
rename from node_modules/imagemin-svgo/index.js
rename to node_modules/imagemin-svgo/index.cjs

This issue body was partially generated by patch-package.

JBaczuk avatar Nov 05 '21 02:11 JBaczuk

When running yarn build I got the same error with the same suggestion your are making or to remove "type": "module" from the package.json file in node_modules/imagemin-svgo/. I decided to go with the first suggestion and changed the index file type of imagemin-svgo to .cjs and now my project is running locally but I am still wondering why did it work and if there will be any impact before releasing it.

Javascript, NodeJS and all the libraries/frameworks derived from or related to them are not my area of expertise so I would really appreciate some insight reggarding this issue.

dchiang avatar Nov 08 '21 20:11 dchiang

If you run into this issue, please see the discussion and links at #57

webketje avatar May 03 '24 18:05 webketje