{"record":{"id":"2a6e2956e2715bbd","repo":"chroma-core/chroma","slug":"please-install-ollama-as-a-dependency-with-e-g","errorCode":null,"errorMessage":"Please install Ollama as a dependency with, e.g. `npm install ollama`","messagePattern":"Please install Ollama as a dependency with, e\\.g\\. `npm install ollama`","errorType":"exception","errorClass":"Error","httpStatus":null,"severity":"error","filePath":"clients/js/packages/chromadb-core/src/embeddings/OllamaEmbeddingFunction.ts","lineNumber":57,"sourceCode":"          \"Please install the ollama package to use the OllamaEmbeddingFunction, `npm install -S ollama`\",\n        );\n      }\n      throw e;\n    }\n  }\n\n  /** @ignore */\n  static async import(): Promise<{\n    // @ts-ignore\n    ollama: typeof import(\"ollama\");\n  }> {\n    try {\n      // @ts-ignore\n      const { ollama } = await import(\"ollama\").then((m) => ({ ollama: m }));\n      // @ts-ignore\n      return { ollama };\n    } catch (e) {\n      throw new Error(\n        \"Please install Ollama as a dependency with, e.g. `npm install ollama`\",\n      );\n    }\n  }\n\n  public async generate(texts: string[]) {\n    await this.initClient();\n    return await this.ollamaClient!.embed({\n      model: this.model,\n      input: texts,\n    }).then((response: any) => {\n      return response.embeddings;\n    });\n  }\n\n  buildFromConfig(config: StoredConfig): OllamaEmbeddingFunction {\n    return new OllamaEmbeddingFunction({\n      url: config.url,","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/chroma-core/chroma/blob/aecdd12c8a891610db8653630b066b32ceb678b5/clients/js/packages/chromadb-core/src/embeddings/OllamaEmbeddingFunction.ts#L39-L75","documentation":"Static import helper for OllamaEmbeddingFunction: it wraps import(\"ollama\") (re-shaping the module as { ollama: m }) in an unconditional try/catch, so every import failure — missing package, broken install, or bundler resolution — becomes the same 'install Ollama' message with the original error discarded. This masks non-obvious causes the same way errors 41/44/57 do.","triggerScenarios":"Any rejection of the dynamic import(\"ollama\") via OllamaEmbeddingFunction.import(): package absent, partially installed, or unresolvable by the runtime/bundler.","commonSituations":"node_modules desync after branch switches; exports-map resolution failures in bundled deployments; optional deps stripped by minimal CI install stages.","solutions":["npm install ollama and retry","If already installed, reproduce the swallowed error: node -e \"import('ollama').then(m=>console.log('ok'),e=>console.error(e))\"","Clean reinstall from the lockfile: rm -rf node_modules && npm ci","Switch embedding functions if the dependency is unwanted"],"exampleFix":"// before: install message despite the package being listed\n// after: expose the real import error the helper swallows\n// $ node -e \"import('ollama').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(\"ollama\"))) {\n  // fail with instructions or fall back to another embedding function\n}","typeGuard":null,"tryCatchPattern":"try {\n  await ef.generate(texts);\n} catch (e) {\n  if (e instanceof Error && /install Ollama/.test(e.message)) {\n    // probe import('ollama') to tell missing package from broken install\n  }\n  throw e;\n}","preventionTips":["Commit lockfiles and use npm ci in CI for reproducible optional deps","CI smoke-import each optional provider package","Prefer explicit embedding functions in bundled/serverless builds"],"tags":["npm","ollama","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"}