找不到模块var http = require('http'),https = require('https'),fs = require('fs')

时间:2018-06-19 03:42:50

标签: node.js http https fs web3

我使用electronic-vue来构建我的项目。执行npm run dev命令时,项目构建失败。以下是错误信息:

  

无法在/ Users / guo / wallet / linkeye-vue-wallet / var http = require('http'),https = require('https'),fs = require('fs'); var doRequest = http.request; var options = {“host”:“localhost”,“port”:“8545”,“path”:“/”,“method”:“POST”,“headers”:{“User -agent “:” 节点的XMLHttpRequest “ ”接受“: ” / “, ”内容类型“: ”应用/ JSON“, ”主机“: ”本地主机:8545“,” 内容 - 长度“:122},”agent“:false,”withCredentials“:false}; var responseText =''; var req = doRequest(options,function(response){response.setEncoding('utf8'); response.on( 'data',function(chunk){responseText + = chunk;}); response.on('end',function(){fs.writeFileSync('。node-xmlhttprequest-content-41081',JSON.stringify({err :null,data:{statusCode:response.statusCode,headers:response.headers,text:responseText}}),'utf8'); fs.unlinkSync('。node-xmlhttprequest-sync-41081');}); response .on('error',function(error){fs.writeFileSync('。node-xmlhttprequest-content-41081',JSON.stringify({err:error}),'utf8'); fs.unli nkSync('。node-xmlhttprequest-sync-41081');});})。on('error',function(error){fs.writeFileSync('。node-xmlhttprequest-content-41081',JSON.stringify( {err:error}),'utf8'); fs.unlinkSync('。node-xmlhttprequest-sync-41081');}); req.write('{\“jsonrpc \”:\“2.0 \”,\ “ID \”:1,\ “方法\”:\ “eth_getTransactionCount \”,\ “PARAMS \”:[\ “8d2f7a66bf0a873662245fa2e59c275a9196a4fe \”,\ “最新\”]}“); req.end();

  

找不到模块'/ Users / guo / wallet / linkeye-vue-wallet / var http = require('http'),https = require('https'),fs = require('fs'); var doRequest = http.request; var options = {“host”:“localhost”,“port”:“8545”,“path”:“/”,“method”:“POST”,“headers”:{“User-Agent “:” 节点的XMLHttpRequest”, “接受”: “ / ”, “内容类型”: “应用/ JSON”, “主机”: “本地主机:8545”, “内容长度” :122},“agent”:false,“withCredentials”:false}; var responseText =''; var req = doRequest(options,function(response)

以下是我的代码

var Web3 = require("web3");

if (typeof web3 !== 'undefined')
{
   console.info('Web3 already initialized, re-using provider.');
   web3 = new Web3(web3.currentProvider);
}
else
{
   console.info('Web3 not yet initialized, doing so now with HttpProvider.');
   web3 = new Web3(new Web3.providers.HttpProvider("http://localhost:8545"));
}

function getTransactionNonce(address){
  if (address == null)
  {
     console.log("address is null");
  }else{
     console.log("enter here")
     var nonce = web3.eth.getTransactionCount(address)
     console.log("the account address" + address + "nonce is " + nonce);
  }
}

exports.getTransactionNonce = getTransactionNonce;

我在另一个代码文件中使用函数getTransactionNonce

0 个答案:

没有答案