Open ram4444 opened 2 days ago
I have confirmed this happens when you are using expo (npx create-expo-app@latest
). You have to configure it to support package exports (please see https://reactnative.dev/blog/2023/06/21/package-exports-support), but it seems not that easy.
I recommend to set up your react native project without expo to see whether the same issue happens
Thanks for your reply.
For the suggestion of set up an react native project without expo, I have tried so but, I can only find the expo one works in metamask-sdk's example git (they have 3 of them one of react-native only example) (They have updated the package.json so that none of them works now unless downgrading to the version which is using "eciesjs": "0.3.20"]
reactNative only example 1 (not work for me) reactNative only example 2 (not work for me) expo example(now i am working on)
According to the article, Package Exports will be enabled for most projects in the next React Native release (0.73) later this year. To upgrade the sample expo sample project from Metamask-sdk's git to latest react-native version (and also the expo version) I have run
npx create-expo-app@latest
starting from the beginning and copy other files back, so that I expected package exports has already been enabled. Now the expo and the react native is in
"expo": "^51.0.0",
"react-native": "0.74.5",
However the same error message does happen.
By adding the line below mentioned in the article
config.resolver.unstable_enablePackageExports= true,
I am getting the error msg of
Android Bundling failed 8291ms node_modules/expo-router/entry.js (3338 modules) The package at "node_modules/@ecies/ciphers/dist/_node/compat.js" attempted to import the Node standard library module "node:crypto". It failed because the native React runtime does not include the Node standard library.
Here is my metro.config.js
//const { getDefaultConfig, mergeConfig } = require("@react-native/metro-config");
// Learn more https://docs.expo.io/guides/customizing-metro
const { getDefaultConfig } = require('expo/metro-config');
const config = getDefaultConfig(__dirname);
config.resolver.extraNodeModules = {
...require("node-libs-expo"),
};
config.resolver.sourceExts = ['jsx', 'js', 'ts', 'tsx', 'cjs', 'json']
config.resolver.unstable_enablePackageExports= true,
config.transformer.getTransformOptions = async () => ({
transform: {
experimentalImportSupport: false,
inlineRequires: true,
},
});
module.exports = config;
I have added react-native exports for @ecies/ciphers
, now it will use pure js implementation so you don't have to polyfill node modules (but you still need to polyfill Buffer and crypto.getRandomBytes)
I'll also publish a react native example soon
Thanks for your reply I will refer this thread to Metamask-SDK team
I've confirmed that it works on React Native with the latest version of @ecies/ciphers
(0.2.1) when package exports enabled
Please update the dependency on ecies as it is still showing 0.2.0
No we don't have to because it's semver ^0.2.0 (>=0.2.0,<0.3.0), you can just pnpm update or yarn upgrade
Hi, I have faced an issue as shown in title when I start my react native app. May you help to investigate the issue behind?
version in package.json "@metamask/sdk": "^0.30.0", "@metamask/sdk-react": "^0.30.0", "eciesjs": "^0.4.10",