【问题标题】:Web3 React Native Expo V4.13Web3 React Native Expo V4.13
【发布时间】:2022-09-30 02:38:46
【问题描述】:

使用 React Native Expo V4.13.0,导入 web3 V1.6.1 模块,我收到以下错误:

Unable to resolve module crypto from /Users/black/Desktop/test/node_modules/web3-eth-accounts/lib/index.js: crypto could not be found within the project or in these directories:
node_modules/web3-eth-accounts/node_modules
node_modules
../../node_modules

如果您确定该模块存在,请尝试以下步骤:

  • 清空守望者手表:watchman watch-del-all
  • 删除节点模块
  • 运行 yarn install 重置 Metro 的缓存: yarn start --reset-cache
  • 删除缓存:rm -rf /tmp/metro-*
24 | var Method = require(\'web3-core-method\');
25 | var Account = require(\'eth-lib/lib/account\');
26 | var cryp = (typeof global === \'undefined\') ? require(\'crypto-browserify\') : require(\'crypto\');
| ^
27 | var scrypt = require(\'scrypt-js\');
28 | var uuid = require(\'uuid\');
29 | var utils = require(\'web3-utils\');`

昨天我更新了 expo 的版本,它不再工作了,在它工作正常之前。

有没有人有同样的问题?

    标签: react-native expo web3js


    【解决方案1】:

    我为此使用了expo-crypto

    在你的项目中安装上面的包yarn add expo-crypto

    在你的 babel.config.js 中添加以下内容

    module.exports = function(api) {
      ...
      return {
        ...
        plugins: [
          [
            'module-resolver',
            {
              alias: {
                crypto: './node_modules/expo-crypto'
              }
            },
          ],
        ]
      };
    };
    `
    

    【讨论】:

      猜你喜欢
      • 2018-09-20
      • 1970-01-01
      • 1970-01-01
      • 2020-03-15
      • 2018-02-12
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多