Open mayank1513 opened 2 years ago
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.
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)
I also had to downgrade "imagemin-mozjpeg": "9.0.0",
from version 10.0.0
to get this to work
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.