crypto.randomBytes不是angular中的函数

crypto.randomBytes不是angular中的函数,angular,Angular,我在安圭拉进口 import EthereumWallet from 'ethereumjs-wallet'; var wallet = EthereumWallet.generate(); const jsV3 = wallet.toV3(passwd); 库中的代码如下所示 var privKey = crypto.randomBytes(32) 抛出错误 错误:未捕获(承诺中):TypeError:crypto.randomBytes为 不是函数类型错误:crypto.randomBy

我在安圭拉进口

import EthereumWallet from 'ethereumjs-wallet';
var wallet = EthereumWallet.generate();
const jsV3 = wallet.toV3(passwd);
库中的代码如下所示

var privKey = crypto.randomBytes(32)
抛出错误

错误:未捕获(承诺中):TypeError:crypto.randomBytes为 不是函数类型错误:crypto.randomBytes不是函数 TypeError:crypto.randomBytes不是函数 在Function.webpackJsonp…/../../../../ethereumjs wallet/index.js.wallet.generate

如何解决

运行

npm安装crypto browserify--保存

之后,您需要创建一个要修复的文件(解决方法)。。。像这样:

var fs = require('fs'); // PACKAGE_ERROR and FILE_ERROR is shown on your error fs.readFile('./node_modules/[PACKAGE_ERROR]/[FILE_ERROR]', 'utf8', function (err,data) { if (err) return console.log(err); var result = data.replace('require(\'crypto\');', 'require(\'crypto-browserify\');'); fs.writeFile('./node_modules/[PACKAGE_ERROR]/[FILE_ERROR]', result, 'utf8', function (err) { if (err) return console.log(err); }); }); var fs=需要('fs'); //包错误和文件错误显示在您的错误页上 fs.readFile(“./node\u modules/[PACKAGE\u ERROR]/[FILE\u ERROR]”,'utf8',函数(err,data){ if(err)返回console.log(err); var result=data.replace('require(\'crypto\');','require(\'crypto-browserify\');'); fs.writeFile(“./node\u modules/[PACKAGE\u ERROR]/[FILE\u ERROR]”,结果为“utf8”,函数为(err){ if(err)返回console.log(err); }); }); 现在,您需要在package.json上添加postinstall代码

... "scripts":{ "postinstall":"node [fixFileName].js", ... ... “脚本”:{ “postinstall”:“节点[fixFileName].js”, ... 要完成,请运行:

npm安装
发球还是发球


我希望这会有帮助!

你有这么多的代表,人们会认为你知道如何提问。一行代码对诊断问题没有帮助:)我更新了问题当我尝试此操作时,我得到:{[Error:enoint:没有这样的文件或目录,open./node\u modules/[PACKAGE\u Error]/[file\u Error]]错误号:-2,代码:“enoint”,系统调用:“open”,路径:“./node\u modules/[PACKAGE\u ERROR]/[FILE\u ERROR]}