bsteo
bsteo

Reputation: 1779

Nodejs "SyntaxError: Unexpected token ."

I'm trying to run a Bitcoin insight explorer (https://www.dgbwiki.com/index.php?title=Running_your_own_Insight_explorer). Using node v0.10.48 but I get this error (couldn't find the same problem over the internet):

digibyte@derecha-virtual-machine:~/insight$ /home/digibyte/.nvm/v0.10.48/bin/node ~/insight/node_modules/insight-bitcore-api/util/sync.js -D -v --rpc

/home/digibyte/insight/node_modules/insight-bitcore-api/node_modules/async/dist/async.js:52
    function apply(fn, ...args) {
                       ^
SyntaxError: Unexpected token .
    at Module._compile (module.js:439:25)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)
    at Function.Module._load (module.js:312:12)
    at Module.require (module.js:364:17)
    at require (module.js:380:17)
    at Object.<anonymous> (/home/digibyte/insight/node_modules/insight-bitcore-api/lib/HistoricSync.js:5:22)
    at Module._compile (module.js:456:26)
    at Object.Module._extensions..js (module.js:474:10)
    at Module.load (module.js:356:32)

The offending line 52 is in this function:

function apply(fn, ...args) { // <- line 52
    return (...callArgs) => fn(...args,...callArgs);
}

It looks ok to me I don't know why node gives an error.

Upvotes: 1

Views: 3245

Answers (3)

Phu Ngo
Phu Ngo

Reputation: 921

According to https://node.green/#ES2015-syntax-rest-parameters, node v0.10.48 does not support rest parameters (...args).

You should use a newer version of node (at least v6.4.0 as default support, or at least v4.9.1 with --harmony flag (node --harmony))

Upvotes: 1

Akash Srivastav
Akash Srivastav

Reputation: 766

Apply takes an array as the second argument. Here, the spread operator (...) is laying out the elements, and thus you don't pass an array into the function, but basically comma separated arguments.

Try using .call instead of .apply, or pass args instead of ...args.

Upvotes: -1

Mureinik
Mureinik

Reputation: 312136

Node.js 0.10.48 doesn't support the spread operator. The first Node.js version to support the spread operator was 5, but it's quite outdated and isn't maintained anymore. If you're already upgrading, I'd upgrade to one of the newer version still supported under LTS.

Upvotes: 2

Related Questions