redis/node-redis · error · Error

The "digest" function requires the "@node-rs/xxhash"…

Error message

The "digest" function requires the "@node-rs/xxhash" package, but it was not found.

What it means

The `digest()` helper computes a deterministic 64-bit XXH3 hash matching Redis's internal DIGEST, used for conditional SET/DELEX operations (`IFDEQ`, `IFDNE`). It lazy-imports `@node-rs/xxhash`, which is an optional peer dependency; if the package cannot be imported, getXxh3() throws this error. The cache means the import is attempted at most once per process.

Solutions

  1. Install the package: `npm install @node-rs/xxhash`.
  2. Ensure optional dependencies are not filtered out in install/CI.
  3. Use the matching platform binary (prebuilt) for your runtime.

Example fix

// before
digest(value) // throws: package missing
// after (terminal)
npm install @node-rs/xxhash
// then in code
digest(value)
Defensive patterns

Strategy: validation

Validate before calling

async function xxhashAvailable(): Promise<boolean> {
  try { await import('@node-rs/xxhash'); return true; } catch { return false; }
}
if (!await xxhashAvailable()) {
  throw new Error('Run: npm install @node-rs/xxhash');
}

Try / catch

let digestFn: ((v: string | Buffer) => Promise<string>) | undefined;
try { digestFn = (await import(/* @vite-ignore */ 'packages/client/lib/utils/digest')).digest; }
catch (e) {
  if (String(e).includes('@node-rs/xxhash')) {
    console.error('Install optional dep: npm i @node-rs/xxhash');
  }
  throw e;
}

Prevention

When it happens

Trigger: Calling `digest(value)` (directly or via IFDEQ/IFDNE command construction) in a project that has not installed `@node-rs/xxhash`. The dynamic import fails and the error is thrown.

Common situations: Using conditional-value commands without adding the optional native dependency; bundler/monorepo that strips optional deps; native binary missing for the platform; npm install with `--omit=optional`.


AI-assisted analysis of redis/node-redis@90fd0652bc (2026-08-11). Data as JSON: /api/errors/356a4903a58d857b. Report an issue: GitHub.

Appendix: source

Thrown at packages/client/lib/utils/digest.ts:13

import { RedisArgument } from '../RESP/types';

type Xxh3Module = typeof import('@node-rs/xxhash').xxh3;

let xxh3Cache: Xxh3Module | null = null;

async function getXxh3(): Promise<Xxh3Module> {
  if (!xxh3Cache) {
    try {
      const module = await import('@node-rs/xxhash');
      xxh3Cache = module.xxh3;
    } catch {
      throw new Error(
        'The "digest" function requires the "@node-rs/xxhash" package, but it was not found.'
      );
    }
  }
  return xxh3Cache;
}

/**
 * Computes a deterministic 64-bit XXH3 digest of the input.
 *
 * This produces the same digest that Redis computes internally via the `DIGEST` command,
 * allowing you to use it with conditional SET and DELEX operations (`IFDEQ`, `IFDNE`).
 *
 * @param value - The value to compute the digest for (string or Buffer)
 * @returns A 16-character lowercase hexadecimal digest
 * @throws If the `@node-rs/xxhash` package is not found
 */
export async function digest(value: RedisArgument): Promise<string> {

View on GitHub (pinned to 90fd0652bc)