1

After installing nodejs from the scratch on a Linux Ubuntu 16.04.1 LTS (tested on 2 different servers, but same result...) browserify generates an incorrect bundle.js due to an extra weird character "Â". It happens only when using Web3 module. My browser throws "Unexpected token" when using it.

...
if (options.value > 0) {
    var constructorAbi = abi.filter(function (json) {
        return json.type === 'constructor' && json.inputs.length === args.length;
    })[0] || {}; // <===============================

    if (!constructorAbi.payable) {
        throw new Error('Cannot send value to non-payable constructor');
    }
}
...

These are the packages I installed:

sudo apt-get update
sudo apt-get install -y nodejs npm git

npm cache clear --force 
npm install -g npm

// A version manager for node.
sudo npm install -g n
sudo n stable
        installed : v7.4.0

sudo npm install -g browserify

sudo npm install -g crypto
npm i --save-dev crypto

sudo npm install -g ethereumjs-util
npm i --save-dev ethereumjs-util

sudo npm install -g ethereumjs-tx
npm i --save-dev ethereumjs-tx

sudo npm install -g web3
npm i --save-dev web3

sudo npm install -g buffer
npm i --save-dev buffer

I also tried reinstalling Web3, but same result:

sudo npm uninstall -g web3
sudo npm install -g web3
npm i --save-dev web3

The modules I am using are the following:

vi main.js
    var crypto = require("crypto");
    var util = require("ethereumjs-util");
    var Tx = require('ethereumjs-tx');
    Web3 = require('web3');
    Buffer = require("buffer").Buffer;

I have found it is Web3 module that makes the bundle.js to incorporate the weird char. By removing the weird char on bundle.js everything works fine.

Trying to find out if this is due to a badly encoded NBSP:

$ sed '25494q;d' bundle.js > line.txt
$ od -c line.txt 
    0000000                                                   }   )   [   0
    0000020   ]       |   | 302 240   {   }   ;  \n
    0000032

Any idea what is the reason of that character being there? Thx!

  • 1
    Looks like an NBSP was used instead of a SPACE. Odd, but I don't think that's wrong in of itself (which Chrome's console seems to confirm with `eval("4\u00A0+5")`.) So maybe a badly encoded NBSP? What's the output of `od -c file.js` for that line? – ikegami Jan 19 '17 at 12:25
  • I modified the question with the output of od -c ... any ideas? Thx! – Juan Ignacio Pérez Sacristán Jan 19 '17 at 12:34
  • 1
    That's the correct UTF-8 encoding of NBSP. So either node.js doesn't expect UTF-8 source files, or it doesn't allow an NBSP as whitespace in source files. I don't know much about node.js, so I can't say more. Was just helping isolate the problem. – ikegami Jan 19 '17 at 12:44
  • Thx. Any linux recipe to replace all utf-8 NBSP with white spaces in a file? – Juan Ignacio Pérez Sacristán Jan 19 '17 at 12:53
  • 1
    `perl -CSDA -pe's/\xA0/ /g'`. See [here](http://stackoverflow.com/q/41742890/589924) for usage. – ikegami Jan 19 '17 at 13:24

0 Answers0