React-Native issue while implementing Langchain

583 Views Asked by At

While trying to use Langchain in my React Native project, I come across this error.

Sets I took to set up enviorment:

  1. installed dependecies: npm install openai
  2. added this code:
import { OpenAI } from "langchain/llms/openai";

const llm = new OpenAI({
  openAIApiKey: OPENAI_API_KEY,
});

const text = "What would be a good company name for a company that makes colorful socks?";

const llmResult = await llm.predict(text);

console.log(llmResult);

When this code runs I result in an error:

ERROR  ReferenceError: Property 'ReadableStream' doesn't exist, js engine: hermes
ERROR  Invariant Violation: "main" has not been registered. This can happen if:
* Metro (the local dev server) is run from the wrong folder. Check if Metro is running, stop it and restart it in the current project.       
* A module failed to load due to an error and `AppRegistry.registerComponent` wasn't called., js engine: hermes

I have tried restarting my metro with no success.

1

There are 1 best solutions below

2
On

I am so glad someone is looking into doing this as well.

You are going to have some issues running langchain on hermes/jsc because the engine running JS will be different to node.js. In your situation you may need to look at pollyfilling ReadableStream in order to get it to work.

Also did you make sure to run npm i langchain