imagemin / imagemin-svgo

SVGO plugin for imagemin

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

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

JBaczuk opened this issue Β· comments

Hi! πŸ‘‹

Firstly, thanks for your work on this project! πŸ™‚

Today I used patch-package to patch imagemin-svgo@10.0.0 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.

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.