Skip to content

Fix git dependency package imports#132

Merged
neubig merged 2 commits into
mainfrom
openhands/fix-git-dependency-exports
Apr 25, 2026
Merged

Fix git dependency package imports#132
neubig merged 2 commits into
mainfrom
openhands/fix-git-dependency-exports

Conversation

@neubig
Copy link
Copy Markdown
Member

@neubig neubig commented Apr 25, 2026

  • A human has tested these changes.

Why

Installing the TypeScript client from a git dependency already builds dist/, but the emitted ESM keeps extensionless relative imports such as ./client/server-client and 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

  • rewrite emitted dist/ import/export specifiers after tsc so relative file imports become .js and directory barrels become /index.js
  • keep prepare building a clean dist/ and add a test:git-dependency smoke test that installs the repo via git+file://...
  • include the new scripts in format checks and simplify prepublishOnly to rely on the build done during prepare

Issue Number

N/A (related to OpenHands/agent-canvas#16)

How to Test

  • npm install --no-fund --no-audit
  • npm run build
  • npm test -- --runInBand
  • npm run test:git-dependency

Video/Screenshots

N/A

Type

  • Bug fix
  • Feature
  • Refactor
  • Breaking change
  • Docs / chore

Notes

  • This PR was created by an AI agent (OpenHands) on behalf of the user.
  • This PR specifically fixes the git-installed subpath exports used by downstream consumers such as agent-server-gui.

@neubig can click here to continue refining the PR

Co-authored-by: openhands <openhands@all-hands.dev>
Co-authored-by: openhands <openhands@all-hands.dev>
@neubig neubig marked this pull request as ready for review April 25, 2026 14:37
@neubig neubig merged commit 4716d2e into main Apr 25, 2026
8 checks passed
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>
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.

2 participants