Web3.js: Uncaught TypeError: Cannot read property 'node' of undefined.

Created on 8 Oct 2018  Â·  14Comments  Â·  Source: ChainSafe/web3.js

Using web3 1.0.0 with infura. Everything was working but now it does not.

clarification needed

Most helpful comment

So I tested some versions:

  • 1.0.0-beta.36 => fails
  • 1.0.0-beta.35 => fails
  • 1.0.0-beta.34 => works

So I rolled back to 1.0.0-beta.34 for now...
Guys, seriously, this version is half a year old. Why is it not working with the two most recent versions, why has it not been fixed yet? 🙄Sending transactions is the most basic thing you want to do on a cryptocurrency network, isn't it?

btw, this is my (typescript) code:

  send = async (wallet: Wallet, receiver: string, amount: number): Promise<any> => {
    const tx = {
      from: wallet.address,
      to: receiver,
      value: this.web3.utils.toHex(this.web3.utils.toWei(`${amount}`, 'ether')),
      gas: 200000,
    }

    const signedTx = await this.web3.eth.accounts.signTransaction(tx, wallet.privateKey);
    return this.web3.eth.sendSignedTransaction(signedTx.rawTransaction)
      .on('receipt', txReceipt => console.log('tx receipt received: ', txReceipt));
  }

All 14 comments

@MuhtasimTanmoy Could you please add a code snippet?

I am working with web3.js in meteor.Need to call some methods in a smart contract.
console.log(web3.version);
gives 1.0.0-beta.36.
Any call to smart contract giving this error.

modules.js?hash=7271ca18827644f7480bc40a4802d23bc9cb95cd:68292 Uncaught TypeError: Cannot read property 'node' of undefined
    at new XMLHttpRequest (modules.js?hash=7271ca18827644f7480bc40a4802d23bc9cb95cd:68292)
    at HttpProvider._prepareRequest (modules.js?hash=7271ca18827644f7480bc40a4802d23bc9cb95cd:68092)
    at HttpProvider.send (modules.js?hash=7271ca18827644f7480bc40a4802d23bc9cb95cd:68121)
    at RequestManager.send (modules.js?hash=7271ca18827644f7480bc40a4802d23bc9cb95cd:32347)
    at sendRequest (modules.js?hash=7271ca18827644f7480bc40a4802d23bc9cb95cd:72820)
    at send (modules.js?hash=7271ca18827644f7480bc40a4802d23bc9cb95cd:72841)
    at Object._executeMethod (modules.js?hash=7271ca18827644f7480bc40a4802d23bc9cb95cd:76793)
    at App.test (SampleTest.jsx:20)
    at HTMLUnknownElement.callCallback (modules.js?hash=7271ca18827644f7480bc40a4802d23bc9cb95cd:9354)
    at Object.invokeGuardedCallbackDev (modules.js?hash=7271ca18827644f7480bc40a4802d23bc9cb95cd:9404)`

Also this undefined node points to

    `_this._userAgent = "Mozilla/5.0 (" + os.type() + " " + os.arch() + ") node.js/" + process.versions.node + " v8/" + process.versions.v8;`

in module.js

Was working fine lately.Not working after update.

`

@MuhtasimTanmoy which version are you using? I got the same error on ^1.0.0-beta.36.
Do you know which version it used to work with?

So I tested some versions:

  • 1.0.0-beta.36 => fails
  • 1.0.0-beta.35 => fails
  • 1.0.0-beta.34 => works

So I rolled back to 1.0.0-beta.34 for now...
Guys, seriously, this version is half a year old. Why is it not working with the two most recent versions, why has it not been fixed yet? 🙄Sending transactions is the most basic thing you want to do on a cryptocurrency network, isn't it?

btw, this is my (typescript) code:

  send = async (wallet: Wallet, receiver: string, amount: number): Promise<any> => {
    const tx = {
      from: wallet.address,
      to: receiver,
      value: this.web3.utils.toHex(this.web3.utils.toWei(`${amount}`, 'ether')),
      gas: 200000,
    }

    const signedTx = await this.web3.eth.accounts.signTransaction(tx, wallet.privateKey);
    return this.web3.eth.sendSignedTransaction(signedTx.rawTransaction)
      .on('receipt', txReceipt => console.log('tx receipt received: ', txReceipt));
  }

@MuhtasimTanmoy I got the same error on ^1.0.0-beta.36. Do you find a solution now?

@MuhtasimTanmoy I got the same error on ^1.0.0-beta.36. Do you find a solution now?

@MuhtasimTanmoy I got the same error on ^1.0.0-beta.36. Do you find a solution now?

I believe the problem is that web3 is not being bundled properly and the client is trying to use xhr2-cookies package instead of the browser's built-in XMLHttpRequest. xhr2-cookies package is for Node.js only, so it throws when process.versions.node is called, which doesn't exist in browsers.

0.20.7 uses xhr2-cookies, while 0.20.6 uses xhr2 package instead which gets bundled properly for the browser.
I have not looked into 1.0.0 but based on @takahser's comment, xhr2-cookies was probably introduced in beta 35.

This error occurs not only infura. I had the exact same error with beta.36 and Ganache. Rolling back to beta.34 solves this for now.

This should be fixed with the PR #2000

receiving TypeError: Cannot read property 'node' of undefined, when attempting to web3.eth.getBlockNumber()

was using 1.0.0-beta.38; just updated to 1.0.0-beta.46, but still no luck


Edit: rolling back to 1.0.0-beta.34 fixes it for me as well.

process.versions.node

I fixed it by specify a value to process.versions.node
process.versions ={node: '11.2.0'}

This got fixed with the new HttpProvider. Feel free to open a new issue if there is still a problem.

But i also have the same problems in web3 v1.2.1~

image

Was this page helpful?
0 / 5 - 0 ratings