I am building a simple Vue-based web application which uses Web3 v1.0.0 (the latest version available). Currently, I'm struggling to make something as simple as the following run:

import Web3 from 'web3'

const api = new Web3(new Web3.providers.HttpProvider('...', 2000))

const batch = new api.eth.BatchRequest()
batch.add(api.eth.getBalance.request('...', 'latest', (err, balance) => console.log({ err, balance })))


This snippet runs fine in the NodeJS environemnt, but throws an error in browser:

xml-http-request.js?37da:91 Uncaught TypeError: Cannot read property 'node' of undefined

A brief investigation gave me the following:

  1. Web3 HTTP provider runs requests using XMLHttpRequest from the xhr2-cookies library
  2. The XMLHttpRequest constructor has the following line in its constructor:

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

Apparently, referencing process in the browser environment maks little sense and eventually causes the application to crash.

I've also checked the dist/web3.js in the web3 repo: it seems to reference xhr2-cookies the very same way.

As a result, I have no idea how is this supposed to work in browser. Any ideas?

  • i have the same problem. could you solve it ? – Mohammad Siavashi Sep 10 '18 at 22:00
  • Nope. I've decided to downgrade to 0.20.x – Alex Kiselev Sep 13 '18 at 12:06
  • Same problem here – pepo Jun 16 at 10:45

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Browse other questions tagged or ask your own question.