DIYgod/RSSHub · error · Error

h64Raw is not supported in Worker shim

Error message

h64Raw is not supported in Worker shim

What it means

Thrown by the Cloudflare Workers shim for xxhash-wasm when h64Raw is invoked. The real xxhash-wasm uses WebAssembly to compute 64-bit hashes, which Workers cannot load here, so the shim only implements h64ToString with a sync BigInt fallback and deliberately throws for the raw-buffer 64-bit API. It exists to fail loudly rather than silently return a wrong value.

Source

Thrown at lib/shims/xxhash-wasm.ts:72

            };
        },
        // h64 methods use async SHA-256 but return sync - this is a limitation
        // In practice, only h64ToString is used and it's called with await xxhash()
        h64: (_input: string, _seed?: bigint): bigint => {
            throw new Error('h64 is not supported in Worker shim, use h64ToString instead');
        },
        h64ToString: (input: string, _seed?: bigint): string => {
            // This needs to be sync to match the API, but we use a simple hash
            // The actual usage in cache.ts awaits xxhash() first, so this works
            let hash = 0n;
            const data = encoder.encode(input);
            for (const byte of data) {
                hash = ((hash << 5n) - hash + BigInt(byte)) & 0xff_ff_ff_ff_ff_ff_ff_ffn;
            }
            return hash.toString(16).padStart(16, '0');
        },
        h64Raw: (_inputBuffer: Uint8Array, _seed?: bigint): bigint => {
            throw new Error('h64Raw is not supported in Worker shim');
        },
        create64: (_seed?: bigint): XXHash<bigint> => {
            throw new Error('create64 is not supported in Worker shim');
        },
    };
}

export default xxhash;

View on GitHub (pinned to bed535e087)

Solutions

  1. Switch the call site to h64ToString(input) which the shim implements (lib/shims/xxhash-wasm.ts:61).
  2. Gate the raw-hash code path so it only runs in the Node build, not the Worker bundle (e.g. dynamic import guarded by environment).
  3. If raw bytes are required, hash a string conversion of the buffer with h64ToString instead of using h64Raw.
  4. Run the route under Node/RSSHub core rather than the Worker shim if 64-bit raw hashing is mandatory.

Example fix

// before
const hash = (await xxhash()).h64Raw(buffer, seed);
// after
const hash = (await xxhash()).h64ToString(Buffer.from(buffer).toString('utf8'), seed);
Defensive patterns

Strategy: type-guard

Validate before calling

function supportsH64Raw(h: any): boolean {
  try { return typeof h.h64Raw === 'function' && /\[native code\]|simpleHash/.test(h.h64Raw.toString()) === false; } catch { return false; }
}
// Safer: feature-detect by source
const api = await xxhash();
if (!('h64Raw' in api) || /Worker shim/.test(String(api.h64Raw))) { /* use h64ToString */ }

Type guard

const isH64RawAvailable = (api: XXHashAPI): boolean => {
  try { api.h64Raw(new Uint8Array(0)); return true; } catch { return false; }
};

Try / catch

try {
  return (await xxhash()).h64Raw(buf, seed);
} catch (e) {
  if (/not supported in Worker shim/.test(String((e as Error).message))) {
    return (await xxhash()).h64ToString(Buffer.from(buf).toString(), seed);
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling xxhash().h64Raw(uint8Array, seed) anywhere in code that runs in the Worker bundle (e.g. lib/utils/cache.ts or any cache key path that resolves to the raw 64-bit API). Also triggered if library code branches on the existence of h64Raw rather than using h64ToString.

Common situations: Porting an existing RSSHub feature that uses xxhash-wasm's h64Raw directly into the Cloudflare Worker build; upgrading a dependency that newly calls h64Raw; running the Worker bundle locally with `wrangler dev` instead of the Node entry.

Related errors


AI-assisted analysis of DIYgod/RSSHub@bed535e087 (2026-08-12). Data as JSON: /api/errors/0ac6ac1076612010. Report an issue: GitHub.