无法解析反应式模块密码 [英] Unable to resolve module crypto in reactnative

查看:120
本文介绍了无法解析反应式模块密码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经在这里发布了此内容,并使用

I have posted this here have created react-native app using

react-native init myapp
added web3 in package.json
npm install
react-native run-ios

但是我收到无法从web3-eth-accounts解析模块加密的错误。有什么办法可以解决

but i am getting the error unable to resolve module crypto from web3-eth-accounts. Is there any way to fix this

无法解析加密货币

推荐答案

Crypto是一个节点js模块,运行React Native时-它使用Javascript Core。加密不包括在其中。当我安装crypto时,我使用了以下软件包:

Crypto is a node js module, when React Native is run - it uses Javascript Core. Crypto isn't include within this. When I installed crypto I used the following package:

https://www.npmjs.com/package/react-native-crypto

说明:

npm i --save react-native-crypto
# install peer deps 
npm i --save react-native-randombytes
react-native link react-native-randombytes
# install latest rn-nodeify 
npm i --save-dev tradle/rn-nodeify
# install node core shims and recursively hack package.json files 
# in ./node_modules to add/update the "browser"/"react-native" field with relevant mappings 
./node_modules/.bin/rn-nodeify --hack --install
rn-nodeify will create a shim.js in the project root directory
// index.ios.js or index.android.js
// make sure you use `import` and not require!  
import './shim.js'
// ...the rest of your code

在您的index.js文件中导入 shim.js

Import shim.js in your index.js file.

完成加密后应该可以使用,如果仍然无法使用,则必须在App.js文件中创建一个const,如下所示:

When you have done that crypto should be made available, if it still doesn't work I had to create a const in my App.js file like so:

export const cryp = require('crypto');

并将其导入所需的组件中。

And import it into the components you need.

更新

我为此做了一个全新的构建,如下:

I've done a fresh build for this, I followed the below:

本机初始化TestApp

按照以上有关加密的说明进行操作。

Follow the instructions above for Crypto.

链接:

react-native链接

反应本地运行iOS

这篇关于无法解析反应式模块密码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆