mem0ai/mem0 · error · Error

The '@aws-sdk/client-bedrock-runtime' package is required to

Error message

The '@aws-sdk/client-bedrock-runtime' package is required to use the AWS Bedrock LLM provider. Install it with: npm install @aws-sdk/client-bedrock-runtime (original error: ${detail})

What it means

The Bedrock LLM lazy-imports @aws-sdk/client-bedrock-runtime on first use (keeping it an optional peer dependency so consumers who use other providers don't pay for it). If the dynamic import fails, the error wraps the original failure with install instructions; the memoized import promise is reset so a later call retries after you install the package.

Source

Thrown at mem0-ts/src/oss/src/llms/aws_bedrock.ts:134

  }

  /**
   * Load the optional AWS SDK on first use.
   *
   * This MUST be a dynamic `import()`, never `require()`: tsup/esbuild rewrite
   * `require()` in the published ESM bundle (`dist/oss/index.mjs`) into a
   * `__require` shim that throws `Dynamic require of "..." is not supported`,
   * so every ESM consumer would hit a dead provider even with the SDK installed.
   */
  private async getSDK(): Promise<BedrockSDK> {
    if (!this.sdkPromise) {
      this.sdkPromise = import("@aws-sdk/client-bedrock-runtime").then(
        (sdk) => sdk as unknown as BedrockSDK,
        (err) => {
          // Let a later call retry rather than caching the rejection forever.
          this.sdkPromise = undefined;
          const detail = err instanceof Error ? err.message : String(err);
          throw new Error(
            "The '@aws-sdk/client-bedrock-runtime' package is required to use the AWS Bedrock LLM provider. " +
              `Install it with: npm install @aws-sdk/client-bedrock-runtime (original error: ${detail})`,
          );
        },
      );
    }
    return this.sdkPromise;
  }

  /** Memoized Bedrock client; an injected `config.client` short-circuits the SDK. */
  private async getClient(): Promise<any> {
    if (this.clientOverride) return this.clientOverride;
    if (!this.clientPromise) {
      this.clientPromise = this.getSDK().then(
        ({ BedrockRuntimeClient }) =>
          new BedrockRuntimeClient(this.clientConfig),
      );
    }

View on GitHub (pinned to 001c235229)

Solutions

  1. Install the SDK: npm/pnpm/bun add @aws-sdk/client-bedrock-runtime
  2. Reinstall or dedupe node_modules if the package is present but the import still fails (pnpm install --force, rm -rf node_modules && npm ci)
  3. When bundling, mark @aws-sdk/client-bedrock-runtime as external so the dynamic import stays runtime-resolved
  4. After installing, retry without restarting construction: the failed import is not cached, but a fresh process is cleanest

Example fix

# before
npm install mem0ai # Bedrock peer not installed

# after
npm install mem0ai @aws-sdk/client-bedrock-runtime
Defensive patterns

Strategy: validation

Validate before calling

async function bedrockSdkAvailable(): Promise<boolean> {
  try { await import("@aws-sdk/client-bedrock-runtime"); return true; }
  catch { return false; }
}
if (!(await bedrockSdkAvailable())) {
  throw new Error("Install @aws-sdk/client-bedrock-runtime before using the Bedrock provider");
}

Type guard

function isMissingBedrockSdk(err: unknown): boolean {
  return err instanceof Error && err.message.includes("@aws-sdk/client-bedrock-runtime' package is required");
}

Try / catch

try { await llm.generateResponse(prompt); }
catch (err) {
  if (err instanceof Error && err.message.includes("package is required to use the AWS Bedrock LLM")) {
    throw new Error("Dependency missing: npm install @aws-sdk/client-bedrock-runtime");
  }
  throw err;
}

Prevention

When it happens

Trigger: Using the Bedrock provider without @aws-sdk/client-bedrock-runtime installed; running the published ESM bundle where the package was accidentally bundled/shimmed (the code comment explains tsup previously turned require() into a throwing __require shim); version conflicts or a corrupted node_modules making the import throw.

Common situations: Fresh install of mem0ai with only Bedrock intended but the optional peer never installed (npm sometimes skips optional peers on legacy installs); monorepo hoisting removing the package; bundlers (webpack/rollup) statically resolving the dynamic import and failing at build time.

Related errors


AI-assisted analysis of mem0ai/mem0@001c235229 (2026-08-15). Data as JSON: /api/errors/f1ac94e2a781b320. Report an issue: GitHub.