Hmbown/CodeWhale · error · TypeError

CodeWhaleRuntimeClient requires a fetch implementation

Error message

CodeWhaleRuntimeClient requires a fetch implementation

What it means

CodeWhaleRuntimeClient's constructor resolves its fetch implementation from options.fetch or globalThis.fetch and throws a TypeError if neither is a function. This guards environments with no global fetch (old Node, some runtimes).

Solutions

  1. Upgrade to Node 18+ (or a runtime with global fetch).
  2. Pass an explicit fetch: new CodeWhaleRuntimeClient({ fetch: require('node-fetch') }).
  3. Verify you pass the option under the exact key `fetch`.

Example fix

// before
const client = new CodeWhaleRuntimeClient({ baseUrl });
// after
const client = new CodeWhaleRuntimeClient({ baseUrl, fetch: globalThis.fetch ?? (await import('node-fetch')).default });
Defensive patterns

Strategy: type-guard

Validate before calling

if (typeof globalThis.fetch !== "function" && !options.fetch) { throw new Error("Provide options.fetch: this runtime has no global fetch"); }

Type guard

const hasFetch = (o = {}) => typeof (o.fetch ?? globalThis.fetch) === "function";
if (!hasFetch(opts)) throw new Error("CodeWhaleRuntimeClient needs a fetch implementation");

Try / catch

try { const c = new CodeWhaleRuntimeClient(opts); } catch (e) { if (e instanceof TypeError && e.message.includes("fetch implementation")) { opts = { ...opts, fetch: require('node-fetch') }; } else throw e; }

Prevention

When it happens

Trigger: new CodeWhaleRuntimeClient() is constructed in an environment where globalThis.fetch is undefined and no options.fetch was passed (or a non-function was passed).

Common situations: Running on Node < 18 without a fetch polyfill; running in a non-browser embedded runtime; accidentally passing fetch: undefined explicitly; passing a wrongly-named option like fetchFn.

Understand the failure class

Background: "not installed", "pip install", "required for": how missing-dependency errors surface across open-source libraries — this error's family across 34 libraries.

Related errors


AI-assisted analysis of Hmbown/CodeWhale@433685b202 (2026-09-15). Data as JSON: /api/errors/90c74966557ce3c0. Report an issue: GitHub.

Appendix: source

Thrown at npm/runtime-sdk/index.js:28

    this.body = options.body;
  }
}

export class RuntimeCapabilityError extends RuntimeApiError {
  constructor(capability, message, options = {}) {
    super(message, options);
    this.name = "RuntimeCapabilityError";
    this.capability = capability;
  }
}

export class CodeWhaleRuntimeClient {
  constructor(options = {}) {
    this.baseUrl = normalizeBaseUrl(options.baseUrl ?? DEFAULT_BASE_URL);
    this.token = options.token ?? null;
    this.fetchImpl = options.fetch ?? globalThis.fetch;
    if (typeof this.fetchImpl !== "function") {
      throw new TypeError("CodeWhaleRuntimeClient requires a fetch implementation");
    }
  }

  async createFleetRun(spec) {
    return this.#jsonRequest("/v1/fleet/runs", {
      method: "POST",
      body: spec,
      capability: "fleet_run_create",
    });
  }

  async startFleetRun(runId) {
    return this.#jsonRequest(`/v1/fleet/runs/${segment(runId)}/start`, {
      method: "POST",
      capability: "fleet_run_start",
    });
  }

View on GitHub (pinned to 433685b202)