Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

require() of ES Module (.\node_modules\imagemin-svgo\index.js) from (.\node_modules\next-optimized-images\lib\loaders\img-loader.js) not supported. #270

Open
mayank1513 opened this issue Nov 2, 2021 · 3 comments

Comments

@mayank1513
Copy link

Hi,

I am getting wired error while trying to use next-optimised-images for nextjs12.x and node16.13.0

require() of ES Module (.\node_modules\imagemin-svgo\index.js) from (.\node_modules\next-optimized-images\lib\loaders\img-loader.js) not supported.

Not able to build the project.

@JBaczuk
Copy link

JBaczuk commented Nov 5, 2021

Same here. Here is the full output:

> Build error occurred
Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/imagemin-svgo/index.js from /Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next-optimized-images/lib/loaders/img-loader.js not supported.
Instead change the require of index.js in /Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next-optimized-images/lib/loaders/img-loader.js to a dynamic import() which is available in all CommonJS modules.
    at requireImageminPlugin (/Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next-optimized-images/lib/loaders/img-loader.js:21:10)
    at getImgLoaderOptions (/Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next-optimized-images/lib/loaders/img-loader.js:50:11)
    at applyImgLoader (/Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next-optimized-images/lib/loaders/img-loader.js:96:28)
    at appendLoaders (/Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next-optimized-images/lib/loaders/index.js:137:14)
    at Object.webpack (/Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next-optimized-images/lib/index.js:62:24)
    at Object.getBaseWebpackConfig [as default] (/Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next/dist/build/webpack-config.js:1327:32)
    at async Promise.all (index 0)
    at async Span.traceAsyncFn (/Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next/dist/trace/trace.js:74:20)
    at async /Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next/dist/build/index.js:315:25
    at async Span.traceAsyncFn (/Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next/dist/trace/trace.js:74:20)
    at async Object.build [as default] (/Users/jbaczuk/Development/Personal/jordan-baczuk/node_modules/next/dist/build/index.js:80:25) {
  code: 'ERR_REQUIRE_ESM'
}
error Command failed with exit code 1.
info Visit https://yarnpkg.com/en/docs/cli/run for documentation about this command.

@vitbokisch
Copy link

vitbokisch commented Nov 14, 2021

The solution is to downgrade imagemin-svgo to version 9.0.0. The latest version (10.0.0) has ES module support only, therefore is not compatible with next-optimized-images package (this package still uses require imports, not ES module import syntax)

@sangel10
Copy link

I also had to downgrade "imagemin-mozjpeg": "9.0.0", from version 10.0.0 to get this to work

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants