Repository navigation
Conversation
…dge)
Every SDK call throws under Deno and other WinterCG runtimes:
TypeError: Failed to construct 'Request':
Argument 2 `client` must be a Deno.HttpClient
`_bind` injects the per-instance client under the `client` key so each
operation runs on the right client. @hey-api/client-fetch then spreads the
whole per-request options object — `client` included — into the fetch
`RequestInit`. Node's undici ignores unknown init fields, so the stray
`client` is harmless there and the test suite (Node) stays green. Deno's
`new Request` validates `client` as a `Deno.HttpClient` and rejects the
hey-api client object, so every call fails before any network I/O on Deno
Deploy, Supabase Edge Functions, Cloudflare Workers, etc.
The `client` selector has already done its job by the time the HTTP method
runs, so strip it from the options before the request is built. Per-instance
isolation (auth interceptor, baseURL, defaultHeaders) is unaffected.
Add tests/request-init.test.ts: asserts the selector never reaches the
RequestInit (captured at `new Request` time, since undici would otherwise
swallow it). Fails on the previous behaviour, passes now.
Verified: `npm test` (177 tests) passes; a Deno smoke calling
`accounts.listAccounts` against a stubbed fetch throws before this change and
succeeds after.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Member
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
Every SDK call throws under Deno and other WinterCG runtimes (Supabase Edge Functions, Deno Deploy, Cloudflare Workers):
It fails before any network I/O, so it looks like a total outage of the SDK on those runtimes. It works on Node, which is why the current test suite doesn't catch it.
Root cause
_bind(src/client.ts) injects this instance's client under theclientkey so each operation runs on the right per-instance client:The generated operation then does
(options?.client ?? client).get({ ...options, url }), and@hey-api/client-fetch@0.6spreads that whole options object —clientincluded — straight into the fetchRequestInit(new Request(url, { ...init, client })).RequestInitfields → the strayclientis harmless → tests stay green.new Requestvalidatesclientas aDeno.HttpClientand rejects the hey-api client object → every call throws.This matters because the SDK's own docs target edge runtimes, and it's currently unusable there (confirmed on
0.2.315→ present through0.2.540).Fix
The
clientselector has already done its job (picking the per-instance client) by the time the HTTP method runs, so strip it from the options before hey-api builds the request. One localized change in the constructor; per-instance isolation (auth interceptor,baseURL,defaultHeaders) is unaffected.Tests
tests/request-init.test.ts— asserts theclientselector never reaches theRequestInit, captured atnew Requesttime (undici would otherwise swallow it and hide the bug). Fails on the previous behaviour, passes with this change.npm test→ 177 passed (including the existingisolation.test.ts).client.accounts.listAccounts()against a stubbedfetchthrows before this change and succeeds after.Notes for maintainers
@hey-api/client-fetchto a version that no longer spreads non-RequestInitkeys, or having_bindavoid theclientfield entirely.workerd) job that runs one real call against a stubfetch— it would guard this whole class of runtime breakage going forward. Happy to add that here if you'd like.