Web3.js: Keccak256 Unexpected Token on Linux/ElementaryOS Loki using Node 0.8.4

Created on 30 Jul 2017  路  10Comments  路  Source: ChainSafe/web3.js

Using Node, I'm trying to import web3.js as a dependency using Node in Terminal. When doing so, Node throws Unexpected Token over a line in the web3 code and I'm unable to find any other instance of users having the same issue.

Terminal I/O is the following:

elem@elem-lean:~/Projects/testProjectg$ node
> Web3 = require('web3')
/home/elem/Projects/hello-world-voting/node_modules/web3/packages/web3-eth-accounts/node_modules/eth-lib/src/account.js:6
const {keccak256, keccak256s} = require("./hash");
      ^
SyntaxError: Unexpected token {
    at exports.runInThisContext (vm.js:53:16)
    at Module._compile (module.js:374:25)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/elem/Projects/hello-world-voting/node_modules/web3/packages/web3-eth-accounts/src/index.js:29:15)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/elem/Projects/hello-world-voting/node_modules/web3/packages/web3-eth/src/index.js:36:16)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)
    at Module.load (module.js:344:32)
    at Function.Module._load (module.js:301:12)
    at Module.require (module.js:354:17)
    at require (internal/module.js:12:17)
    at Object.<anonymous> (/home/elem/Projects/hello-world-voting/node_modules/web3/src/index.js:34:11)
bug

Most helpful comment

@MaiaVictor i add your new version but still get the error, e.g. when adding it to a meteor app backend with no babel enabled:

W20170808-14:49:27.797(2)? (STDERR) /Users/frozeman/Sites/_testdrive/meteor-test2/node_modules/web3/packages/web3-eth-accounts/node_modules/eth-lib/src/account.js:6
W20170808-14:49:27.894(2)? (STDERR) const {keccak256, keccak256s} = require("./hash");
W20170808-14:49:27.895(2)? (STDERR)       ^
W20170808-14:49:27.896(2)? (STDERR)
W20170808-14:49:27.897(2)? (STDERR) SyntaxError: Unexpected token {
W20170808-14:49:27.898(2)? (STDERR)     at exports.runInThisContext (vm.js:53:16)
...

All 10 comments

~i am assuming your node is to old and doesn't support ES6.~
@MaiaVictor is there a way to transpire your project before its used by other projects?

EDIT: I see youre using 0.8.4,then i am a bit confused what could be the problem here.

Same issue. fresh build

root@mew-parity-2:~# node

Web3 = require('web3')
/root/node_modules/web3/packages/web3-eth-accounts/node_modules/eth-lib/src/account.js:6
const {keccak256, keccak256s} = require("./hash");
^
SyntaxError: Unexpected token {
at exports.runInThisContext (vm.js:53:16)
at Module._compile (module.js:374:25)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/root/node_modules/web3/packages/web3-eth-accounts/src/index.js:29:15)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/root/node_modules/web3/packages/web3-eth/src/index.js:36:16)
at Module._compile (module.js:410:26)
at Object.Module._extensions..js (module.js:417:10)
at Module.load (module.js:344:32)
at Function.Module._load (module.js:301:12)
at Module.require (module.js:354:17)
at require (internal/module.js:12:17)
at Object. (/root/node_modules/web3/src/index.js:34:11)

Sure, [email protected] is transpiled now. Please message me directly when something like that is needed. (I won't be paying attention to issues until next month.)

Please see if the next release beta.17 will fix this for you. If so please close.

@MaiaVictor i add your new version but still get the error, e.g. when adding it to a meteor app backend with no babel enabled:

W20170808-14:49:27.797(2)? (STDERR) /Users/frozeman/Sites/_testdrive/meteor-test2/node_modules/web3/packages/web3-eth-accounts/node_modules/eth-lib/src/account.js:6
W20170808-14:49:27.894(2)? (STDERR) const {keccak256, keccak256s} = require("./hash");
W20170808-14:49:27.895(2)? (STDERR)       ^
W20170808-14:49:27.896(2)? (STDERR)
W20170808-14:49:27.897(2)? (STDERR) SyntaxError: Unexpected token {
W20170808-14:49:27.898(2)? (STDERR)     at exports.runInThisContext (vm.js:53:16)
...

It's still an issue. Reverted back to an old version.

same issue on ubuntu and nodejs
it works if i use 0.20 version npm install web3@^0.20.0

Have same problem in IE11.
const {keccak256, keccak256s} = __webpack_require__("../../../../web3/packages/web3-eth
Project from Angular 4, node v 6.10

Should be solved in the next version, otherwise please reopen

I'm confused. Did frozeman's 9/15 commit fix this issue? Should it be working in version 0.20.2?

Was this page helpful?
0 / 5 - 0 ratings