Skip to content

v4.2.0 CLI fails with ERR_REQUIRE_ESM on multimatch dependency #1340

@AshotPoghosyan

Description

@AshotPoghosyan

Expected Behavior

The CLI should obfuscate JavaScript files without errors, as it did in version 4.1.1.

Current Behavior

The CLI fails immediately with an ESM compatibility error when trying to load the multimatch dependency.

Steps to Reproduce

  1. Install Node.js v20.x
  2. Run npm install -g javascript-obfuscator@4.2.0
  3. Create a simple JS file: echo "console.log('test')" > test.js
  4. Run javascript-obfuscator test.js --output out.js
  5. Error occurs

My Environment

  • Obfuscator version used: 4.2.0
  • Node version used: v20.15.1 (Alpine Linux / Docker)

Stack trace

Error [ERR_REQUIRE_ESM]: require() of ES Module /usr/local/lib/node_modules/javascript-obfuscator/node_modules/multimatch/index.js from /usr/local/lib/node_modules/javascript-obfuscator/dist/index.cli.js not supported.
  Instead change the require of index.js in /usr/local/lib/node_modules/javascript-obfuscator/dist/index.cli.js to a dynamic import() which is available in all CommonJS modules.
      at 8014 (/usr/local/lib/node_modules/javascript-obfuscator/dist/index.cli.js:2:520165)
      at r (/usr/local/lib/node_modules/javascript-obfuscator/dist/index.cli.js:2:615438)
      at 9632 (/usr/local/lib/node_modules/javascript-obfuscator/dist/index.cli.js:2:586510)
      at r (/usr/local/lib/node_modules/javascript-obfuscator/dist/index.cli.js:2:615438)
      at 2676 (/usr/local/lib/node_modules/javascript-obfuscator/dist/index.cli.js:2:143491)

Minimal working example that will help to reproduce issue

# Any JavaScript file will trigger the error
echo "console.log('hello')" > test.js
javascript-obfuscator test.js --output out.js

Root cause: The multimatch dependency was likely updated to an ESM-only version which cannot be required() from CommonJS.

Workaround: Pin to version 4.1.1

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions