Skip to content

Update crypto imports to support React Native #76

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

amrmelsayed
Copy link

@amrmelsayed amrmelsayed commented Jun 9, 2025

@mme I am trying to run the typescript-sdk in a React Native / Expo environment using the Metro bundler, I got a build error due to the package's reliance on crypto:

The package at "apps/dojo-rn/node_modules/@ag-ui/langgraph/dist/index.js" attempted to import the Node standard library module "crypto".
It failed because the native React runtime does not include the Node standard library.

I am currently employing a polyfill using expo-standard-web-crypto combined with a package patch to resolve this issue, here is a sample of the patch I am currently using @ag-ui+langgraph+0.0.1-alpha.0.patch

It basically replaces the ot=require("crypto") with ot={randomUUID:()=>global.crypto.randomUUID()} that is supplied via a polyfill.

This PR basically replaces the direct crypto imports and function calls with UUID v11 which is already an existing dependency, this can then be combined with expo-standard-web-crypto in React Native / Expo projects to provide the required polyfill without additional patches https://github.com/expo/expo/tree/main/packages/expo-standard-web-crypto.

Fixes #79.

@amrmelsayed amrmelsayed marked this pull request as draft June 13, 2025 06:33
@amrmelsayed
Copy link
Author

amrmelsayed commented Jun 13, 2025

@mme Thanks a lot for your time today, I had another look at the RN client implementation, I don't think we need this patch in particular as these dependencies are expected to run server side, I think this is probably an issue on my end as I set up a combined React Native project that uses AG-UI in mobile app mode (Android, iOS) and CopilotKit in React Native Web, I think the issue is in CopilotKit, don't worry about this PR for now, I think we just need to update CopilotKit's uuid dependency to version 11 to work around an issue related to mixing commonjs and ESM modules, I will have a look and follow-up.

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

Successfully merging this pull request may close these issues.

React Native Crypto Dependency Error
1 participant