Fix ESM binary resolution in JavaScript client#65
Open
evanniedojadlo wants to merge 1 commit intoVibiumDev:mainfrom
Open
Fix ESM binary resolution in JavaScript client#65evanniedojadlo wants to merge 1 commit intoVibiumDev:mainfrom
evanniedojadlo wants to merge 1 commit intoVibiumDev:mainfrom
Conversation
## Problem When using Vibium in an ESM project (with "type": "module" in package.json), the library failed to locate the platform-specific clicker binary, even when correctly installed. The workaround required manually setting CLICKER_PATH. ## Root Cause The binary resolution code in `binary.ts` used `require.resolve()` which is a CommonJS function that doesn't work properly in ESM environments. When Node.js loads the ESM version (`dist/index.mjs`), `require` is not available. ## Solution Implemented dual CJS/ESM support using `createRequire()` from Node's built-in `module` package: - Detects runtime environment by checking for `__filename` (CJS) vs `import.meta.url` (ESM) - Uses `createRequire()` to create a working require function in both environments - Maintains full backwards compatibility with CommonJS projects ## Testing Verified the fix works in both modes: - ✓ ESM mode: Browser launches without CLICKER_PATH - ✓ CommonJS mode: Backwards compatibility maintained - ✓ Existing test suite: 21/23 tests pass (2 pre-existing failures unrelated to this fix) In Vibium fashion, I leveraged Claude Code to identify and address this issue, then personally tested and verified the fixes on macOS 26.1. Co-Authored-By: Claude Sonnet 4.5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Fixes #62 - Vibium fails to locate the clicker binary when used as an ES Module. When using Vibium in an ESM project (with
"type": "module"in package.json), the library failed to find the platform-specific clicker binary, even though it was correctly installed innode_modules/@vibium/{platform}-{arch}/bin/clicker.In Vibium fashion, I leveraged Claude Code to identify and address this issue, then personally tested and verified the fixes on macOS 26.1.
The Fix
The root cause was that
binary.tsusedrequire.resolve()to locate the platform package, which is a CommonJS function that doesn't work in ESM environments.Solution: Implement dual CJS/ESM support using
createRequire():createRequirefrom Node's built-inmodulepackage__filename(CJS) vsimport.meta.url(ESM)requirefunction usingcreateRequire()that works in both environmentsKey changes in
clients/javascript/src/clicker/binary.ts:Test plan
"type": "module", verified browser launches without CLICKER_PATHTesting with Claude Code
To reproduce the issue and verify the fix:
Reproduce the issue (before fix):
Verify the fix (after):
Claude Code prompts for testing:
🤖 Generated with Claude Code