This topic was originally posted by mynameisjerry870203 on 5/20/2024.
This content has been migrated from our previous community forum to preserve valuable discussions.
import Web3Auth from '@web3auth/modal';
import { CHAIN_NAMESPACES, IProvider, WEB3AUTH_NETWORK } from '@web3auth/base';
import SolanaPrivateKeyProvider from '@web3auth/solana-provider';
whenever I put this in code, it pops out
Error: undefined Unable to resolve module crypto from /Users/jhinresh/Desktop/Recivo_wallet/node_modules/@web3auth/base-provider/node_modules/@toruslabs/eccrypto/dist/eccrypto.cjs.js: crypto could not be found within the project or in these directories:
node_modules/@web3auth/base-provider/node_modules
node_modules
../../node_modules
Especially
import Web3Auth from '@web3auth/modal';
import SolanaPrivateKeyProvider from '@web3auth/solana-provider';
I have taken a look into the troubleshooting, put polyfills file, adjusted metro.config.js and add globals.js, still not sure what i missed.
I donât think you need to import a polyfill file directly in App.tsx. Instead, we handle polyfilling within the metro.config.js file and use a globals.js file, which is imported into App.tsx. Hereâs how your metro.config.js should look, assuming you are working on a Bare React Native App:
const config = {
resolver: {
extraNodeModules: {
assert: require.resolve(âempty-moduleâ), // assert can be polyfilled here if needed
http: require.resolve(âempty-moduleâ), // stream-http can be polyfilled here if needed
https: require.resolve(âempty-moduleâ), // https-browserify can be polyfilled here if needed
os: require.resolve(âempty-moduleâ), // os-browserify can be polyfilled here if needed
url: require.resolve(âempty-moduleâ), // url can be polyfilled here if needed
zlib: require.resolve(âempty-moduleâ), // browserify-zlib can be polyfilled here if needed
path: require.resolve(âempty-moduleâ),
crypto: require.resolve(âcrypto-browserifyâ),
stream: require.resolve(âreadable-streamâ),
},
sourceExts: [âŚdefaultConfig.resolver.sourceExts, âsvgâ],
},
};