我正在构建一个Ethereum ERC20令牌支持钱包在React本地,我一直在这个特别的问题上挣扎了几天,我希望有人能帮助。
该包位于“Node _ module /web3-ETH-Account/src/index.js”,试图导入Node标准库模块"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
发布于 2019-07-13 12:52:44
我有两个答案:)
1)使用ethers.js,因为它很丰富,并且具有默认的
2)从提供给项目的链接中复制shims,并将其导入到App.js文件的顶部,以便web3库能够工作。
发布于 2019-07-14 10:19:05
您可以使用.babelrc文件定义可选配置,首先安装依赖项:
您可以尝试安装npm install --save crypto-browserify
然后将插件配置添加到.babelrc文件中:
{
"presets": ["babel-preset-expo"],
"env": {
"development": {
"plugins": ["transform-react-jsx-source"]
}
},
"plugins": [
["module-resolver", {
"root": ["./app"],
"alias": {
"crypto": "crypto-browserify"
}
}]
]
}请进口钱包模块。
import crypto from 'crypto'您可以运行npm i --save-dev rn-nodeify@latest和rn-nodeify --install "stream"
如果不是./node_modules/.bin/rn-nodeify --install "stream"
rn-nodeify将在项目根目录中创建一个shim.js。
示例
// index.ios.js or index.android.js or App.js
// make sure you use `import` and not `require`!
import './shim.js'



https://stackoverflow.com/questions/57015563
复制相似问题