Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Async_hooks cannot be used in browser #81

Open
Hehongyuanlove opened this issue Mar 7, 2024 · 13 comments
Open

Async_hooks cannot be used in browser #81

Hehongyuanlove opened this issue Mar 7, 2024 · 13 comments

Comments

@Hehongyuanlove
Copy link

Hehongyuanlove commented Mar 7, 2024

I'm using chat_agent_executor_with_function_calling

The same code deno can run, but react cannot run in the browser

node -v

v21.7.0

expo

C:\xxxxx\node_modules@langchain\langgraph\dist\setup\async_local_storage.js:5 Uncaught TypeError: _async_hooks.AsyncLocalStorage is not a constructor
at initializeAsyncLocalStorageSingleton (C:\xxxxx\node_modules@langchain\langgraph\dist\setup\async_local_storage.js:5:2)
at new Pregel (C:\xxxxxt\node_modules@langchain\langgraph\dist\pregel\index.js:159:51)
at StateGraph.compile (C:\xxxxx\node_modules@langchain\langgraph\dist\graph\state.js:90:13)
at C:\xxxxx\page\tool\index.tsx:164:21
at loadModuleImplementation (C:\xxxxx\node_modules\metro-runtime\src\polyfills\require.js:282:19)
at guardedLoadModule (C:\xxxxx\node_modules\metro-runtime\src\polyfills\require.js:182:1)
at metroRequire (C:\xxxxx\node_modules\metro-runtime\src\polyfills\require.js:91:43)
at C:\xxxxx\App.js:4:44
at loadModuleImplementation (C:\xxxxx\node_modules\metro-runtime\src\polyfills\require.js:282:19)
at guardedLoadModule (C:\xxxxx\node_modules\metro-runtime\src\polyfills\require.js:182:1)

@bracesproul
Copy link
Collaborator

cc @jacoblee93 related to AsyncLocalStorage

@jacoblee93
Copy link
Collaborator

jacoblee93 commented Mar 12, 2024

Oh shoot 😬

Will see if we can add web entrypoints to mitigate this I suppose.

@demchuk-alex
Copy link

Hey @jacoblee93 having the same issue, tring to use langgraphjs in react-native app, and nextjs.
Sorry for nudging is there any news or work arounds ?

@jacoblee93
Copy link
Collaborator

Thank you for nudging - will try my best to look this week!

@davidfant
Copy link

davidfant commented Mar 26, 2024

@jacoblee93 I'm also running into this. It happens when my NextJS imports a file that also imports @langchain/langgraph. I did this bc I shared types between frontend and backend, so frontend imported langgraph which otherwise was just used on the backend.

@demchuk-alex making the frontend only import my types and not langgraph solved my problem

@demchuk-alex
Copy link

demchuk-alex commented Mar 27, 2024

Oh thanks @davidfant you mean do not import like Pregel type, since graph.compile() returns this type ?
In my case it's eventually needs to work in react native not in nextJS, unfortunately :(

compile() {
   ..... some code
    return new Pregel({
      nodes,
      input: `${this.entryPoint}:inbox`,
      output: END,
      hidden,
      checkpointer,
    });
}

where Pregel callsnitializeAsyncLocalStorageSingleton(); inside the constructor and needs async_hook's AsyncStorage.

@jacoblee93
Copy link
Collaborator

jacoblee93 commented Mar 27, 2024

Yeah exactly that. The solution I'm thinking of is to add a separate Pregel class that doesn't use hooks for web. Only issue is that it's super convenient for tracing 😕

@demchuk-alex
Copy link

Agree @jacoblee93 or pass some param to compile to turn off tracing for web or pass your tracing something like that 👍

@jacoblee93
Copy link
Collaborator

jacoblee93 commented Mar 27, 2024

Sorry when I say tracing it also affects things like streamEvents too so we do still want to make sure config is getting populated even if you're not using tracing. It'll just make a bunch of our examples broken when streaming intermediate steps, we'll have to document it well.

@demchuk-alex
Copy link

@jacoblee93 fair enough 👍

@demchuk-alex
Copy link

Hey @jacoblee93 sorry for nudging again :) did you have a chance to make it available for web ? Thanks

@jacoblee93
Copy link
Collaborator

Still on the TODO list - sorry for the delay.

@Luiz-N
Copy link

Luiz-N commented May 24, 2024

So fair to say lang graph js does not work in the browser currently?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants