[英]Nodejs "SyntaxError: Unexpected token ."
我正在嘗試運行一個比特幣洞察瀏覽器( https://www.dgbwiki.com/index.php?title=Running_your_own_Insight_explorer )。 使用 node v0.10.48 但我收到此錯誤(無法通過 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)
有問題的第 52 行在這個函數中:
function apply(fn, ...args) { // <- line 52
return (...callArgs) => fn(...args,...callArgs);
}
對我來說看起來沒問題我不知道為什么節點會出錯。
Node.js 0.10.48 不支持擴展運算符。 第一個支持擴展運算符的 Node.js 版本是 5,但它已經過時並且不再維護。 如果您已經在升級,我會升級到 LTS 下仍受支持的較新版本之一。
根據https://node.green/#ES2015-syntax-rest-parameters ,節點 v0.10.48 不支持其余參數( ...args
)。
您應該使用節點的新版本(至少V6.4.0作為默認支持,或與至少v4.9.1 --harmony
標志( node --harmony
))
Apply 將數組作為第二個參數。 在這里, spread
運算符 ( ...
) 正在布置元素,因此您不會將數組傳遞給函數,而是基本上以逗號分隔的參數。
嘗試使用.call
代替.apply
,或通過args
代替...args
。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.