langchain-ai / langchainjs

🦜🔗 Build context-aware reasoning applications 🦜🔗
https://js.langchain.com/docs/
MIT License
12.41k stars 2.1k forks source link

Package subpath './weaviate' is not defined by "exports" #4500

Closed Slyke closed 7 months ago

Slyke commented 7 months ago

Hello, I'm following the instructions at: https://weaviate.io/developers/weaviate/client-libraries/typescript

But getting errors even with simple code.

Code:

import { Ollama } from "@langchain/community/llms/ollama";
import { OllamaEmbeddings } from "@langchain/community/embeddings/ollama";
import weaviate, { ApiKey } from "weaviate-ts-client";
import { WeaviateStore } from "langchain/weaviate"; // <-- This line is causing the error.

const client = weaviate.client({
  scheme: process.env.WEAVIATE_SCHEME || "https",
  host: process.env.WEAVIATE_HOST || "localhost",
  apiKey: new ApiKey(process.env.WEAVIATE_API_KEY || ""),
});

const ollama = new Ollama({
  baseUrl: "http://localhost:11434",
  model: "llama2",
});

const embeddings = new OllamaEmbeddings({
  model: "llama2",
  baseUrl: "http://localhost:11434",
});

await WeaviateStore.fromTexts(
  ["hello world", "hi there", "how are you", "bye now"],
  [{ foo: "bar" }, { foo: "baz" }, { foo: "qux" }, { foo: "bar" }],
  embeddings,
  {
    client,
    indexName: "Test",
    textKey: "text",
    metadataKeys: ["foo"],
  }
);

Run:

npm init
# Ensure to add '"type": "module"' to package.json so import works.
npm install -S langchain
npm install @langchain/community
npm install @langchain/core
npm install weaviate-ts-client
node test.js

Error message:

node:internal/modules/esm/resolve:303
  return new ERR_PACKAGE_PATH_NOT_EXPORTED(
         ^

Error [ERR_PACKAGE_PATH_NOT_EXPORTED]: Package subpath './weaviate' is not defined by "exports" in /home/slyke/path/to/app/node_modules/langchain/package.json imported from /home/slyke/path/to/app/test.js
    at exportsNotFound (node:internal/modules/esm/resolve:303:10)
    at packageExportsResolve (node:internal/modules/esm/resolve:650:9)
    at packageResolve (node:internal/modules/esm/resolve:836:14)
    at moduleResolve (node:internal/modules/esm/resolve:910:20)
    at defaultResolve (node:internal/modules/esm/resolve:1130:11)
    at ModuleLoader.defaultResolve (node:internal/modules/esm/loader:396:12)
    at ModuleLoader.resolve (node:internal/modules/esm/loader:365:25)
    at ModuleLoader.getModuleJob (node:internal/modules/esm/loader:240:38)
    at ModuleWrap.<anonymous> (node:internal/modules/esm/module_job:85:39)
    at link (node:internal/modules/esm/module_job:84:36) {
  code: 'ERR_PACKAGE_PATH_NOT_EXPORTED'
}
dosubot[bot] commented 7 months ago

🤖

Hey there @Slyke! 👋 I'm Dosu, a friendly bot here to help you squash bugs, answer questions, and get you contributing in no time while we wait for a human maintainer. I'm diving into your issue and will get back to you with a full answer shortly! Stay tuned. 🤖

Slyke commented 7 months ago

Fix:

Run:

npm install @langchain/weaviate

Put an @ on the front of the import:

import { WeaviateStore } from "@langchain/weaviate";