Skip to content

Fix #62: Resolve clicker binary path in ES Module context#75

Open
bluerook2000 wants to merge 1 commit intoVibiumDev:mainfrom
bluerook2000:fix/issue-62-esm-clicker-path
Open

Fix #62: Resolve clicker binary path in ES Module context#75
bluerook2000 wants to merge 1 commit intoVibiumDev:mainfrom
bluerook2000:fix/issue-62-esm-clicker-path

Conversation

@bluerook2000
Copy link
Copy Markdown

Summary

Fixes #62 — Vibium fails to locate the clicker binary when used in ESM projects ("type": "module" in package.json).

Problem

The getClickerPath() function used require.resolve() to find the platform-specific binary package. In ESM context, require is not available, causing the resolution to fail with:

Error: Could not find clicker binary. Set CLICKER_PATH environment variable or install @vibium/darwin-x64

Solution

Added a resolvePackageJson() helper that:

  1. Tries native require.resolve() first (works in CJS)
  2. Falls back to createRequire() from the module builtin (works in ESM)

The createRequire approach creates a require function anchored to process.cwd(), which correctly resolves packages from the project's node_modules.

Verification

  • tsup build succeeds for both CJS and ESM formats
  • ESM bundle correctly uses createRequire fallback (tsup transforms require__require in ESM, so the CJS branch naturally skips)
  • No changes to CJS behavior — existing require.resolve path still works

Files Changed

  • clients/javascript/src/clicker/binary.ts — Added ESM-compatible package resolution

Use createRequire from 'module' as fallback when native require.resolve
is unavailable (ESM context). This fixes the binary resolution for
projects using "type": "module" in package.json.

Fixes VibiumDev#62
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.

Vibium fails to locate clicker binary when used as ES Module

1 participant