{"record":{"id":"f1ac94e2a781b320","repo":"mem0ai/mem0","slug":"the-aws-sdk-client-bedrock-runtime-package-is-r","errorCode":null,"errorMessage":"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})","messagePattern":"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: (.+?)\\)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/llms/aws_bedrock.ts","lineNumber":134,"sourceCode":"  }\n\n  /**\n   * Load the optional AWS SDK on first use.\n   *\n   * This MUST be a dynamic `import()`, never `require()`: tsup/esbuild rewrite\n   * `require()` in the published ESM bundle (`dist/oss/index.mjs`) into a\n   * `__require` shim that throws `Dynamic require of \"...\" is not supported`,\n   * so every ESM consumer would hit a dead provider even with the SDK installed.\n   */\n  private async getSDK(): Promise<BedrockSDK> {\n    if (!this.sdkPromise) {\n      this.sdkPromise = import(\"@aws-sdk/client-bedrock-runtime\").then(\n        (sdk) => sdk as unknown as BedrockSDK,\n        (err) => {\n          // Let a later call retry rather than caching the rejection forever.\n          this.sdkPromise = undefined;\n          const detail = err instanceof Error ? err.message : String(err);\n          throw new Error(\n            \"The '@aws-sdk/client-bedrock-runtime' package is required to use the AWS Bedrock LLM provider. \" +\n              `Install it with: npm install @aws-sdk/client-bedrock-runtime (original error: ${detail})`,\n          );\n        },\n      );\n    }\n    return this.sdkPromise;\n  }\n\n  /** Memoized Bedrock client; an injected `config.client` short-circuits the SDK. */\n  private async getClient(): Promise<any> {\n    if (this.clientOverride) return this.clientOverride;\n    if (!this.clientPromise) {\n      this.clientPromise = this.getSDK().then(\n        ({ BedrockRuntimeClient }) =>\n          new BedrockRuntimeClient(this.clientConfig),\n      );\n    }","sourceCodeStart":116,"sourceCodeEnd":152,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/llms/aws_bedrock.ts#L116-L152","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Install the SDK: npm/pnpm/bun add @aws-sdk/client-bedrock-runtime","Reinstall or dedupe node_modules if the package is present but the import still fails (pnpm install --force, rm -rf node_modules && npm ci)","When bundling, mark @aws-sdk/client-bedrock-runtime as external so the dynamic import stays runtime-resolved","After installing, retry without restarting construction: the failed import is not cached, but a fresh process is cleanest"],"exampleFix":"# before\nnpm install mem0ai # Bedrock peer not installed\n\n# after\nnpm install mem0ai @aws-sdk/client-bedrock-runtime","handlingStrategy":"validation","validationCode":"async function bedrockSdkAvailable(): Promise<boolean> {\n  try { await import(\"@aws-sdk/client-bedrock-runtime\"); return true; }\n  catch { return false; }\n}\nif (!(await bedrockSdkAvailable())) {\n  throw new Error(\"Install @aws-sdk/client-bedrock-runtime before using the Bedrock provider\");\n}","typeGuard":"function isMissingBedrockSdk(err: unknown): boolean {\n  return err instanceof Error && err.message.includes(\"@aws-sdk/client-bedrock-runtime' package is required\");\n}","tryCatchPattern":"try { await llm.generateResponse(prompt); }\ncatch (err) {\n  if (err instanceof Error && err.message.includes(\"package is required to use the AWS Bedrock LLM\")) {\n    throw new Error(\"Dependency missing: npm install @aws-sdk/client-bedrock-runtime\");\n  }\n  throw err;\n}","preventionTips":["Declare @aws-sdk/client-bedrock-runtime in your own package.json when using the Bedrock provider","Mark it external in bundler configs so the dynamic import stays runtime-resolved","Probe the import at startup to fail fast with an actionable message"],"tags":["aws-bedrock","dependencies","installation","esm","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T17:31:12.345Z"}