react-native - 位于 "node_modules/web3-eth-accounts/src/index.js"的包试图导入 Node 标准库模块 "crypto"

标签 react-native expo web3js

我正在用 React Native 构建一个以太坊 ERC20 代币支持钱包,过去几天我一直在为这个特殊问题苦苦挣扎,我希望有人能提供帮助。

The package at "node_modules/web3-eth-accounts/src/index.js" attempted to import the Node standard library module "crypto"

这是我的 package.json 文件。

"dependencies": {
    "expo": "^33.0.0",
    "react": "16.8.3",
    "react-dom": "^16.8.6",
    "react-native": "https://github.com/expo/react-native/archive/sdk-33.0.0.tar.gz",
    "react-native-web": "^0.11.4",
    "socket.io-client": "^2.2.0",
    "web3": "1.0.0-beta.34",
    "cryptico": "^1.0.2",
    "native-base": "2.8.0",
    "node-libs-browser": "2.1.0",
    "react-native-crypto": "^2.0.0",
    "react-native-randombytes": "^2.0.0"
  },
  "devDependencies": {
    "babel-preset-expo": "^5.1.1",
    "babel-cli": "6.26.0",
    "babel-preset-es2015": "6.24.1"
  },

请指教! 我也关注了这个链接,没有运气! https://gist.github.com/dougbacelar/29e60920d8fa1982535247563eb63766

最佳答案

我有 2 个答案给你:)

1) 使用 ethers.js 因为它很丰富并且默认支持 React Native

2) 从您提供给项目的链接复制垫片并将其导入顶部的 App.js 文件,这样您的 web3 库就可以工作了

关于react-native - 位于 "node_modules/web3-eth-accounts/src/index.js"的包试图导入 Node 标准库模块 "crypto",我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57015563/

相关文章:

javascript - Calendar.createEventAsync 仅在 Android 博览会上崩溃

python - 为什么 web3.eth.getBlock 给出空答案而 getTransactionReceipt 给出错误?

ethereum - Solidity 和 Web3js : EIP712 signing uint256 works signing uint256[] does not

javascript - 带有 React-native 的推送器订阅,setState 更新

react-native - 方法或属性 expo-file-system.downloadAsync 在 android 上不可用,您确定您已正确链接所有 native 依赖项吗?

css - React-Native 中的双模态?

ethereum - web3 getAccounts 未得到解决

windows - 在 Android 模拟器上运行时出现 Expo 警告

javascript - 在 Visual Studio Code 中自动导入以进行 React-Native 开发

android - StackNavigator 中的 TabNavigator - React Native