[英]Error: attempted to import the Node standard library module “crypto”. It failed
I was going to use ethereumjs-wallet
. 我打算用ethereumjs-wallet
。 But I decided to use ethereumjs-wallet-react-native
because it's for the web. 但我决定使用ethereumjs-wallet-react-native
因为它适用于网络。 If you look at the link , it says import
the two modules. 如果你查看链接 ,它会说import
两个模块。 So I took two modules and tried to import
them, but there was a problem. 所以我拿了两个模块并尝试import
它们,但是有一个问题。
an error-causing code: 导致错误的代码:
import { asyncRandomBytes } from 'react-native-secure-randombytes'
import safeCrypto from 'react-native-safe-crypto'
window.randomBytes = asyncRandomBytes
window.scryptsy = safeCrypto.scrypt
Errormessage: 错误信息:
Unable to resolve module "react-native-secure-randombytes" 无法解析模块“react-native-secure-randombytes”
I wanted to solve this problem, but I couldn't solve it, so I decided to take a detour. 我想解决这个问题,但我无法解决,所以我决定绕道而行。
Error Resolved Code: 错误已解决代码:
import safeCrypto from "react-native-fast-crypto";
const { RNRandomBytes } = NativeModules;
window.randomBytes = RNRandomBytes.randomBytes;
window.scryptsy = safeCrypto.scrypt;
This may cause problems later, but it's settled for now. 这可能会在以后引起问题,但现在已经解决了。 However, there was another problem when we called up and executed ethereumjs-wallet-react-native.
但是,当我们调用并执行ethereumjs-wallet-react-native.
时,还有另一个问题ethereumjs-wallet-react-native.
errormessage: 错误信息:
The package at "node_modules/ethereumjs-wallet-react-native/index.js" attempted to import the Node standard library module "crypto". “node_modules / ethereumjs-wallet-react-native / index.js”中的包试图导入节点标准库模块“crypto”。 It failed because React Native does not include the Node standard library. 它失败了,因为React Native不包含Node标准库。 Read more at https://docs.expo.io/versions/latest/introduction/faq/#can-i-use-nodejs-packages-with-expo 更多信息, 请访问https://docs.expo.io/versions/latest/introduction/faq/#can-i-use-nodejs-packages-with-expo
So I downloaded crypto-browserify
, but it didn't work. 所以我下载了crypto-browserify
,但它没有用。
Code that attempted to resolve 试图解决的代码
import safeCrypto from "react-native-fast-crypto";
const { RNRandomBytes } = NativeModules;
import Wallet from "ethereumjs-wallet-react-native";
var crypto = require("crypto-browserify");
window.randomBytes = RNRandomBytes.randomBytes;
window.scryptsy = safeCrypto.scrypt;
...
async componentDidMount() {
const wallet = await Wallet.generate();
}
this is package.json: 这是package.json:
"dependencies": {
"crypto-browserify": "^3.12.0",
"ethereumjs-wallet-react-native": "^0.6.7",
"expo": "^32.0.0",
"expokit": "32.1.1",
"react": "16.5.0",
"react-native": "https://github.com/expo/react-native/archive/sdk-32.0.0.tar.gz",
"react-native-fast-crypto": "^1.8.1",
"react-native-randombytes": "^3.5.2"
},
"devDependencies": {
"babel-preset-expo": "^5.0.0"
},
The code for "ethereumjs-wallet-react-native/index.js" is located on the link in my article. “ethereumjs-wallet-react-native / index.js”的代码位于我文章的链接中。
Please help us. 请帮助我们。 Thank you in advance. 先感谢您。
react-native-randombytes
were Re-link. react-native-randombytes
是Re-link。
and 和
I was used import crypto from "crypto";
我import crypto from "crypto";
使用了import crypto from "crypto";
Recreate Successful Code 重新创建成功的代码
import crypto from "crypto";
import safeCrypto from "react-native-fast-crypto";
import { asyncRandomBytes } from "react-native-secure-randombytes";
...
window.randomBytes = asyncRandomBytes;
window.scryptsy = safeCrypto.scrypt;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.