mem0ai/mem0 · error · Error

The ' ' package is required to use the . Install it with…

Error message

The '${pkg}' package is required to use the ${label}. Install it with: npm install ${pkg}

What it means

loadPeer is a helper that dynamically imports optional peer dependencies (e.g. @azure/search-documents, mysql2, mochow-sdk); if the dynamic import fails it rethrows a friendly message naming the missing package and the npm install command. It exists because provider-specific SDKs are optional peers so that importing mem0ai/oss does not require every backend. The original error is swallowed, so only the package name is reported.

Solutions

  1. Run the npm install command shown in the message (e.g. npm install mysql2).
  2. If already installed, reinstall node_modules (rm -rf node_modules && npm install) to fix a broken resolution.
  3. With pnpm/yarn workspaces, ensure the dependency is declared in the package that actually imports mem0ai, not only the root.

Example fix

# before
npm install mem0ai   # then use Azure MySQL store -> error
# after
npm install mem0ai mysql2
Defensive patterns

Strategy: try-catch

Validate before calling

async function peerAvailable(pkg: string): Promise<boolean> {
  try { await import(pkg); return true; } catch { return false; }
}

Try / catch

try {
  await memory.add(msgs, { userId });
} catch (e) {
  if (e instanceof Error && /package is required to use/.test(e.message)) {
    // extract pkg name and surface 'run npm install <pkg>' to the operator
  }
  throw e;
}

Prevention

When it happens

Trigger: Configuring a vector store such as Azure AI Search or Azure MySQL without having installed its SDK (npm install @azure/search-documents / mysql2); using a bundler or pnpm strict node_modules layout that cannot resolve the peer; a corrupted node_modules causing the import to throw.

Common situations: Fresh install of mem0ai where optional peers are skipped; monorepo hoisting issues; CI image lacking optional deps; error message tells exactly which package to add.

Related errors


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

Appendix: source

Thrown at mem0-ts/src/oss/src/utils/load_peer.ts:9

export async function loadPeer(
  pkg: string,
  label: string,
  load: () => Promise<any>,
): Promise<any> {
  try {
    return await load();
  } catch {
    throw new Error(
      `The '${pkg}' package is required to use the ${label}. Install it with: npm install ${pkg}`,
    );
  }
}

View on GitHub (pinned to 001c235229)