Skip to content

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

@sbhavani

Description

@sbhavani

Bug Description

The @agent-tars/cli package fails to run on Node.js v18, v20, and v22 due to an ESM/CommonJS incompatibility with the imagemin-mozjpeg dependency.

Error Message

Error [ERR_REQUIRE_ESM]: require() of ES Module /Users/sbhavani/.nvm/versions/node/v18.20.8/lib/node_modules/@agent-tars/cli/node_modules/imagemin-mozjpeg/index.js from /Users/sbhavani/.nvm/versions/node/v18.20.8/lib/node_modules/@agent-tars/cli/node_modules/@agent-tars/core/dist/index.js not supported.
Instead change the require of /Users/sbhavani/.nvm/versions/node/v18.20.8/lib/node_modules/@agent-tars/cli/node_modules/imagemin-mozjpeg/index.js in /Users/sbhavani/.nvm/versions/node/v18.20.8/lib/node_modules/@agent-tars/core/dist/index.js to a dynamic import() which is available in all CommonJS modules.
    at ./src/shared/utils.ts (/Users/sbhavani/.nvm/versions/node/v18.20.8/lib/node_modules/@agent-tars/cli/node_modules/@agent-tars/core/dist/index.js:134699:59)

Steps to Reproduce

  1. Install @agent-tars/cli globally: npm install -g @agent-tars/cli
  2. Run any agent-tars command: agent-tars --help
  3. Error occurs immediately

Environment

  • Node.js versions tested: v18.20.8, v20.18.3, v22.18.0
  • npm version: 10.8.2
  • OS: macOS (Darwin 24.6.0)
  • @agent-tars/cli version: Latest (0.3.0-beta.12)

Root Cause

The issue appears to be in the webpack bundling configuration. The bundled CommonJS code is attempting to require() the imagemin-mozjpeg package, which is now an ES module only. This creates an incompatibility that prevents the CLI from running.

The error occurs at:

  • File: @agent-tars/core/dist/index.js:134699
  • Location: ./src/shared/utils.ts

Suggested Fix

The bundling configuration needs to be updated to either:

  1. Use dynamic import() for ESM-only dependencies like imagemin-mozjpeg
  2. Exclude ESM-only dependencies from the webpack bundle and load them dynamically at runtime
  3. Convert the entire package to ESM format

Workaround

Currently, there is no working workaround. The package is unusable across all tested Node.js versions.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions