{"record":{"id":"1f90df8acebd3da0","repo":"mem0ai/mem0","slug":"the-pkg-package-is-required-to-use-the-labe","errorCode":null,"errorMessage":"The '${pkg}' package is required to use the ${label}. Install it with: npm install ${pkg}","messagePattern":"The '(.+?)' package is required to use the (.+?)\\. Install it with: npm install (.+?)","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"mem0-ts/src/oss/src/utils/load_peer.ts","lineNumber":9,"sourceCode":"export async function loadPeer(\n  pkg: string,\n  label: string,\n  load: () => Promise<any>,\n): Promise<any> {\n  try {\n    return await load();\n  } catch {\n    throw new Error(\n      `The '${pkg}' package is required to use the ${label}. Install it with: npm install ${pkg}`,\n    );\n  }\n}\n","sourceCodeStart":1,"sourceCodeEnd":14,"githubUrl":"https://github.com/mem0ai/mem0/blob/001c235229be8795e3834520467bd0d661ed8f34/mem0-ts/src/oss/src/utils/load_peer.ts#L1-L14","documentation":"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.","triggerScenarios":"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.","commonSituations":"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.","solutions":["Run the npm install command shown in the message (e.g. npm install mysql2).","If already installed, reinstall node_modules (rm -rf node_modules && npm install) to fix a broken resolution.","With pnpm/yarn workspaces, ensure the dependency is declared in the package that actually imports mem0ai, not only the root."],"exampleFix":"# before\nnpm install mem0ai   # then use Azure MySQL store -> error\n# after\nnpm install mem0ai mysql2","handlingStrategy":"try-catch","validationCode":"async function peerAvailable(pkg: string): Promise<boolean> {\n  try { await import(pkg); return true; } catch { return false; }\n}","typeGuard":null,"tryCatchPattern":"try {\n  await memory.add(msgs, { userId });\n} catch (e) {\n  if (e instanceof Error && /package is required to use/.test(e.message)) {\n    // extract pkg name and surface 'run npm install <pkg>' to the operator\n  }\n  throw e;\n}","preventionTips":["Declare the backend SDK (mysql2, @azure/search-documents, mochow-sdk, @azure/identity) in package.json alongside mem0ai from day one.","Run a startup health check that dynamically imports each peer your config needs.","In monorepos, install the peer in the consuming package, not just the root."],"tags":["dependencies","peer-dependency","npm","typescript"],"backgroundTag":null,"analyzedSha":"001c235229be8795e3834520467bd0d661ed8f34","analyzedAt":"2026-08-15T01:55:42.685Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}