{"record":{"id":"54550ad26c87a89f","repo":"chroma-core/chroma","slug":"please-install-google-generative-ai-as-a-dependen","errorCode":null,"errorMessage":"Please install @google/generative-ai as a dependency with, e.g. `npm install @google/generative-ai`","messagePattern":"Please install @google/generative-ai as a dependency with, e\\.g\\. `npm install @google/generative-ai`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/embeddings/GoogleGeminiEmbeddingFunction.ts","lineNumber":94,"sourceCode":"    });\n    const embeddings = response.embeddings.map((e: any) => e.values);\n\n    return embeddings;\n  }\n\n  /** @ignore */\n  static async import(): Promise<{\n    // @ts-ignore\n    googleGenAi: typeof import(\"@google/generative-ai\");\n  }> {\n    try {\n      // @ts-ignore\n      const { GoogleGenerativeAI } = await import(\"@google/generative-ai\");\n      const googleGenAi = GoogleGenerativeAI;\n      // @ts-ignore\n      return { googleGenAi };\n    } catch (e) {\n      throw new Error(\n        \"Please install @google/generative-ai as a dependency with, e.g. `npm install @google/generative-ai`\",\n      );\n    }\n  }\n\n  buildFromConfig(config: StoredConfig): GoogleGenerativeAiEmbeddingFunction {\n    return new GoogleGenerativeAiEmbeddingFunction({\n      model: config.model_name,\n      apiKeyEnvVar: config.api_key_env_var,\n      taskType: config.task_type,\n    });\n  }\n\n  getConfig(): StoredConfig {\n    return {\n      api_key_env_var: this.api_key_env_var,\n      model_name: this.model,\n      task_type: this.taskType,","sourceCodeStart":76,"sourceCodeEnd":112,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/GoogleGeminiEmbeddingFunction.ts#L76-L112","documentation":"Static import helper for the Google embedding function: it wraps import(\"@google/generative-ai\") in an unconditional try/catch, so every import failure — missing package, broken install, or bundler resolution — becomes the same 'install it as a dependency' message. The original error is discarded, which can mask non-obvious causes. Note the import destructures the named/default GoogleGenerativeAI export, so it targets the legacy @google/generative-ai package specifically.","triggerScenarios":"Any rejection of import(\"@google/generative-ai\") via GoogleGenerativeAiEmbeddingFunction.import(): package absent, half-installed, or unresolvable by the bundler/runtime.","commonSituations":"node_modules desync after branch switches; teams migrating to the newer @google/genai SDK and assuming the old one is present; bundler exports-map failures in Lambda/edge builds; optional deps stripped by minimal install stages.","solutions":["npm install @google/generative-ai (the legacy package this function expects, not @google/genai)","If it is installed, reproduce the swallowed error: node -e \"import('@google/generative-ai').then(m=>console.log('ok'),e=>console.error(e))\"","Clean reinstall from the lockfile: rm -rf node_modules && npm ci","Use a different embedding function if you do not want the dependency"],"exampleFix":"// before: install message despite presence in package.json\n// after: expose the real import error the helper swallows\n// $ node -e \"import('@google/generative-ai').then(m=>console.log('ok'), e=>console.error(e))\"","handlingStrategy":"validation","validationCode":"async function canImport(pkg: string): Promise<boolean> {\n  try {\n    await import(pkg);\n    return true;\n  } catch {\n    return false;\n  }\n}\nif (!(await canImport(\"@google/generative-ai\"))) {\n  // choose another embedding function or fail with instructions\n}","typeGuard":null,"tryCatchPattern":"try {\n  await ef.generate(texts);\n} catch (e) {\n  if (e instanceof Error && /@google\\/generative-ai/.test(e.message)) {\n    // probe the import to distinguish missing vs broken install\n  }\n  throw e;\n}","preventionTips":["Pin the Google SDK version in package.json rather than relying on hoisting","CI smoke-import each optional provider SDK","Prefer explicit embedding functions over lazy-loaded providers in bundled deployments"],"tags":["npm","google","gemini","module-not-found","error-masking","embeddings"],"backgroundTag":"module-not-found","analyzedSha":"aecdd12c8a891610db8653630b066b32ceb678b5","analyzedAt":"2026-08-16T21:53:27.228Z","schemaVersion":2},"datasetVersion":"2026-08-16T23:17:17.608Z"}