I am getting this error which I do not understand and am not able to fix.
The code is,
const fs = require('fs')
const Web3 = require('web3')
const { NonceTxMiddleware, SignedTxMiddleware, LocalAddress, CryptoUtils, HDWalletProvider } = require('#truffle/hdwallet-provider')
const client = new Client (
goerliChainId,
"https://eth-goerli.g.alchemy.com/v2/zEsvEP-zdgrdgdffgfgf64kuugnfvd6P",
"https://eth-goerli.g.alchemy.com/v2/oqB3MrwE1sdfgsdfgsdfgy5WD71Qj24n"
)
The error message is,
const client = new Client (
^
ReferenceError: Client is not defined
at Object.loadAccount (C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\utils\common.js:13:20)
at init (C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\Oracle.js:128:53)
at C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\Oracle.js:138:60
at Object.<anonymous> (C:\Users\VidhanMangla\Desktop\mqube-blockchain-oracle\Oracle.js:149:3)
at Module._compile (node:internal/modules/cjs/loader:1218:14)
at Module._extensions..js (node:internal/modules/cjs/loader:1272:10)
at Module.load (node:internal/modules/cjs/loader:1081:32)
at Module._load (node:internal/modules/cjs/loader:922:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:23:47
I am not able to understand anything, please help.
Related
const {web3js, myAccount} = require ('./utils')
const {bytecode} = require ('./contractartifact')
async function deploy() {
web3js.eth.sendTransaction({
from: myAccount.address,
data: bytecode,
gas: 800
})
.on('receipt', console.log)
}
deploy()
Error
C:\Users\giris\getter-setter\deploy.js:9
web3js.eth.sendTransaction({
^
TypeError: Cannot read properties of undefined (reading 'eth')
at deploy (C:\Users\giris\getter-setter\deploy.js:9:12)
at Object. (C:\Users\giris\getter-setter\deploy.js:19:1)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules /cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12)
at node:internal/main/run_main_module:17:47
Your import is incorrect here:
const {web3js, myAccount} = require ('./utils')
It should be:
const web3js = new Web3(Web3.givenProvider || "ws://localhost:8545");
MyCode;
eventHandler.js
const reqEvent = async(event) => require(`../events/${event}`);
module.exports = async(client) => {
client.on("ready", () => reqEvent("ready")(client, "message"));
client.on("message", () => reqEvent("message"));
}
y client definition
const client = new Discord.Client({
intents: [
Discord.Intents.FLAGS.GUILDS,
Discord.Intents.FLAGS.GUILD_MEMBERS,
Discord.Intents.FLAGS.GUILD_MESSAGES,
Discord.Intents.FLAGS.GUILD_MESSAGE_REACTIONS,
Discord.Intents.FLAGS.GUILD_VOICE_STATES
]
});
Error;
TypeError [ERR_INVALID_ARG_TYPE]: The "listener" argument must be of type function. Received an instance of Promise
at checkListener (node:events:128:3)
at _addListener (node:events:423:3)
at Client.addListener (node:events:487:10)
at module.exports (/app/util/eventHandler.js:5:12)
at Object.<anonymous> (/app/index.js:15:34)
at Module._compile (node:internal/modules/cjs/loader:1101:14)
at Object.Module._extensions..js (node:internal/modules/cjs/loader:1153:10)
at Module.load (node:internal/modules/cjs/loader:981:32)
at Function.Module._load (node:internal/modules/cjs/loader:822:12)
at Function.executeUserEntryPoint [as runMain] (node:internal/modules/run_main:81:12) {
code: 'ERR_INVALID_ARG_TYPE'
}
I can't solve this error, can anyone help with the solution?
I Used Google Translate. I'm Sorry If I Have Any Mistakes.
try this
module.exports = async(client) => {
client.on("message", (message)=> {
reqEvent(message.content);
});
};
I am new to nodejs and trying to write this web scraper where I am getting the following errors. It asks to return promise however I tried but nothing works out. Not sure if I am using the right packages. Promises in async is quite difficult to understand for me at this point. Any explanation along with the code will be really apprciated.
PS C:\Users\farid\Desktop\Node Projects\webscraping> node --trace-warnings .\index.js (node:10748) UnhandledPromiseRejectionWarning: RequestError: Error: Invalid URI "0"
at new RequestError (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\errors.js:14:15)
at Request.plumbing.callback (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\plumbing.js:87:29)
at Request.RP$callback [as _callback] (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\plumbing.js:46:31)
at self.callback (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:185:22)
at Request.emit (events.js:315:20)
at Request.init (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:273:17)
at Request.RP$initInterceptor [as init] (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\configure\request2.js:45:29)
at new Request (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:127:8)
at request (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\index.js:53:10)
at C:\Users\farid\Desktop\Node Projects\webscraping\index.js:13:26
at Object.<anonymous> (C:\Users\farid\Desktop\Node Projects\webscraping\index.js:50:3)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
at emitUnhandledRejectionWarning (internal/process/promises.js:168:15)
at processPromiseRejections (internal/process/promises.js:247:11)
at processTicksAndRejections (internal/process/task_queues.js:94:32)
(node:10748) RequestError: Error: Invalid URI "0"
at new RequestError (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\errors.js:14:15)
at Request.plumbing.callback (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\plumbing.js:87:29)
at Request.RP$callback [as _callback] (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\lib\plumbing.js:46:31)
at self.callback (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:185:22)
at Request.emit (events.js:315:20)
at Request.init (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:273:17)
at Request.RP$initInterceptor [as init] (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request-promise-core\configure\request2.js:45:29)
at new Request (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\request.js:127:8)
at request (C:\Users\farid\Desktop\Node Projects\webscraping\node_modules\request\index.js:53:10)
at C:\Users\farid\Desktop\Node Projects\webscraping\index.js:13:26
at Object.<anonymous> (C:\Users\farid\Desktop\Node Projects\webscraping\index.js:50:3)
at Module._compile (internal/modules/cjs/loader.js:1063:30)
at Object.Module._extensions..js (internal/modules/cjs/loader.js:1092:10)
at Module.load (internal/modules/cjs/loader.js:928:32)
at Function.Module._load (internal/modules/cjs/loader.js:769:14)
at Function.executeUserEntryPoint [as runMain] (internal/modules/run_main.js:72:12)
at internal/main/run_main_module.js:17:47
(node:10748) [DEP0018] DeprecationWarning: Unhandled promise rejections are deprecated. In the future, promise rejections that are not handled will terminate the Node.js process with a non-zero exit code.
at emitDeprecationWarning (internal/process/promises.js:180:11)
at processPromiseRejections (internal/process/promises.js:249:13)
at processTicksAndRejections (internal/process/task_queues.js:94:32)
PS C:\Users\farid\Desktop\Node Projects\webscraping>
Here is my index.js file code.
const request = require("request-promise");
const cheeri = require("cheerio");
const fs = require("fs")
const json2csv = require("json2csv").Parser;
const web_urls = ["https://www.gillmanacura.com/" , "https://www.gillmanacura.com/service/contact-service/"];
// const web_urls = ["https://www.fernandezhonda.com/trade-in-calculator/"];
(async() => {
let emptyData = [];
for(let web_url in web_urls){
let resp = await request({
uri: web_url,
headers:{},
timeout:10000,
json: true,
gzip: true
});
let $ = cheeri.load(resp)
let title = $('head title').text()
let desc = $('meta[name="description"]').attr('content')
let canonical = $('link[rel="canonical"]').attr('href')
let kwd = $('meta[name="keywords"]').attr('content')
let ogTitle = $('meta[property="og:title"]').attr('content')
let ogImage = $('meta[property="og:image"]').attr('content')
let ogkeywords = $('meta[property="og:keywords"]').attr('content')
emptyData.push({
title,
desc,
canonical,
kwd,
ogTitle,
ogImage,
ogkeywords
});
}
const j2csv = new json2csv()
const csv = j2csv.parse(emptyData)
fs.writeFileSync("./results.csv", csv, "utf-8");
})();
How can I resolve these errors? Please advise.
Use for of instead of in. in will iterate over the keys and of over the values.
for(let web_url in web_urls){
I am facing an issue while running my compile.js file using node compile.js .
My code:
const async = require('asyncawait/async');
const await = require('asyncawait/await');
const HDWalletProvider = require('truffle-hdwallet-provider');
const Web3 = require('web3');
const { interface, bytecode } = require('./compile');
const provider = new HDWalletProvider(
'nut plug quality level uncle jeans retire guide eagle gossip cluster sudden',
'https://rinkeby.infura.io/v3/37097b2064214600912ad8a746ff433a'
);
const web3 = new Webs(provider);
const deploy = async (() => {
const accounts = await (web3.eth.Accounts());
console.log('Attempting to deploy from account', accounts[0]);
const result = await(new web3.eth.Contract(JSON.parse(interface))
.deploy({ data: bytecode, arguments: ['Hi there!'] })
.send({gas: '1000000', from: accounts[0]})
);
console.log('contract deployed to', result.options.address);
});
deploy();
After running : node compile.js
Error log:
/home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js:38
async awaitCurrentBlock () {
^^^^^^^^^^^^^^^^^
SyntaxError: Unexpected token function
at createScript (vm.js:56:10)
at Object.runInThisContext (vm.js:97:10)
at Module._compile (module.js:542:28)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
at require (internal/module.js:20:19)
at Object.<anonymous> (/home/edureka/sankalp_practice/inbox/node_modules/web3-provider-engine/index.js:4:25)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.require (module.js:497:17)
I did my analysis and it seems that "const HDWalletProvider = require('truffle-hdwallet-provider');" is calling for function async awaitCurrentBlock () in /home/edureka/sankalp_practice/inbox/node_modules/eth-block-tracker/src/index.js.
So please let me know how to resolve it.
system: Ubuntu
version of node: v6.11.4
version of npm : 5.4.2
your dependency uses "async awaitCurrentBlock" that looks like node 8.* in which case you're simply using too old version of node. You want that dependency, then you have to update, but that will break your code in another way -> you're importing dependencies "async" and "await" which are reserved keywords in Node 8, so you'll have to update your syntax too
I have an issue that I can't seem to resolve, mostly because I have little knowledge of why it is occurring in this particular scenario.
Here's the error :
TypeError: Cannot read property 'followers' of undefined
at Object.<anonymous> (C:\Users\username\Documents\My Lib\bot\src\bot.js:15:4)
at Module._compile (module.js:570:32)
at Object.Module._extensions..js (module.js:579:10)
at Module.load (module.js:487:32)
at tryModuleLoad (module.js:446:12)
at Function.Module._load (module.js:438:3)
at Module.runMain (module.js:604:10)
at run (bootstrap_node.js:393:7)
at startup (bootstrap_node.js:150:9)
at bootstrap_node.js:508:3
and here's what the code looks like :
const Twit = require('twit'),
config = require('./config'),
init = new Twit(config);
function Twitter(twitter) {
this.twitter = twitter
}
Twitter.prototype.followers = function(params) {
this.twitter.get('followers/list', params, (err, data) => {
if (!err)
data.users.forEach(user => console.log(data))
})
};
var bot = Twitter(init);
bot.followers({ screen_name: 'myscreenname'})
Haha. I'm almost certain it's a silly mistake. I just can't seem to find the source.
Any help is and will be appreciated.
You forgot the new keyword. Try this:
var bot = new Twitter(init);