Fix git dependency package imports#132
Merged
Merged
Conversation
Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
1 task
rbren
pushed a commit
that referenced
this pull request
May 10, 2026
Both `websocket-client.ts` and `bash-websocket-client.ts` ran a
runtime `if (typeof window !== 'undefined') { ... } else { require('ws') }`
block at module load time. Because this package is published as ESM
(`"type": "module"`), `require` is undefined at runtime, so the
`try { require('ws') }` always threw a ReferenceError and the `catch`
re-threw "WebSocket implementation not available. Install ws package
for Node.js environments." — breaking every Node.js ESM consumer of
the library regardless of whether they ever opened a WebSocket.
This logic was latent for months but only became visible to Node.js
consumers after PR #132 made ESM resolution actually succeed for git
installs of the package.
Replace the runtime detection with a simple `globalThis.WebSocket`
lookup (works in browsers, Web Workers, and Node.js >= 22 by default;
Node 21 with `--experimental-websocket`). If no WebSocket is found,
surface a clear error via the existing `onError` callback at
`connect()` time instead of crashing at module load.
Co-authored-by: openhands <openhands@all-hands.dev>
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.
Why
Installing the TypeScript client from a git dependency already builds
dist/, but the emitted ESM keeps extensionless relative imports such as./client/server-clientand directory barrels such as./hooks. Node cannot resolve those paths when the package is consumed directly from GitHub, which breaks downstream imports like@openhands/typescript-client/clients.Summary
dist/import/export specifiers aftertscso relative file imports become.jsand directory barrels become/index.jspreparebuilding a cleandist/and add atest:git-dependencysmoke test that installs the repo viagit+file://...prepublishOnlyto rely on the build done duringprepareIssue Number
N/A (related to OpenHands/agent-canvas#16)
How to Test
npm install --no-fund --no-auditnpm run buildnpm test -- --runInBandnpm run test:git-dependencyVideo/Screenshots
N/A
Type
Notes
agent-server-gui.@neubig can click here to continue refining the PR