Skip to content

fix(shared-media-utils): use dynamic imports for ESM-only imagemin packages#1833

Open
Br1an67 wants to merge 1 commit intobytedance:mainfrom
Br1an67:fix/issue-1700-esm-compat
Open

fix(shared-media-utils): use dynamic imports for ESM-only imagemin packages#1833
Br1an67 wants to merge 1 commit intobytedance:mainfrom
Br1an67:fix/issue-1700-esm-compat

Conversation

@Br1an67
Copy link

@Br1an67 Br1an67 commented Mar 1, 2026

Summary

Fixes #1700

The imagemin ecosystem packages (v8+) are ESM-only, but shared-media-utils builds to CJS, causing ERR_REQUIRE_ESM at runtime. Static import statements for imagemin, imagemin-mozjpeg, imagemin-pngquant, and imagemin-webp fail when the consuming code runs in a CJS context.

Changes:

  • Replaced static imports with dynamic import() helper functions for all imagemin packages
  • Made getPluginsForFormat() async (was sync) since plugins are now loaded dynamically
  • Updated compressToBuffer() to await the dynamic imagemin import

This allows the CJS build output to load ESM-only packages at runtime via dynamic import.

Checklist

  • Added or updated necessary tests (Optional).
  • Updated documentation to align with changes (Optional).
  • Verified no breaking changes, or prepared solutions for any occurring breaking changes (Optional).
  • My change does not involve the above items.

…ckages

imagemin-mozjpeg, imagemin-webp, imagemin-pngquant, and imagemin v8+ are
ESM-only packages that cannot be require()'d from CJS output. The
shared-media-utils package builds to CJS format, causing ERR_REQUIRE_ESM
at runtime.

Replace static imports with dynamic import() calls which work in both
CJS and ESM contexts.

Closes bytedance#1700
@netlify
Copy link

netlify bot commented Mar 1, 2026

Deploy Preview for agent-tars-docs ready!

Name Link
🔨 Latest commit 3369eef
🔍 Latest deploy log https://app.netlify.com/projects/agent-tars-docs/deploys/69a46ea774aae3000876c647
😎 Deploy Preview https://deploy-preview-1833--agent-tars-docs.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

@netlify
Copy link

netlify bot commented Mar 1, 2026

Deploy Preview for tarko ready!

Name Link
🔨 Latest commit 3369eef
🔍 Latest deploy log https://app.netlify.com/projects/tarko/deploys/69a46ea779eb9500084a300d
😎 Deploy Preview https://deploy-preview-1833--tarko.netlify.app
📱 Preview on mobile
Toggle QR Code...

QR Code

Use your smartphone camera to open QR code link.

To edit notification comments on pull requests, go to your Netlify project configuration.

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

Successfully merging this pull request may close these issues.

ERR_REQUIRE_ESM: @agent-tars/cli fails to run due to imagemin-mozjpeg ESM incompatibility

1 participant