簡體   English   中英

nodejs SyntaxError:意外令牌

[英]nodejs SyntaxError: Unexpected token

我正在使用elasticsearch-exporterElasticsearch導出數據。

該工具最初是一個nodejs應用程序。

當我嘗試使用以下命令node exporter.js使該工具列出所有可用選項時,它崩潰,但出現以下異常

/home/me/storage/Elasticsearch-Exporter/log.js:54
exports.error = (...args) => !capture("ERROR", args) && console.log(timestamp() + util.format(...args).red);
                 ^^^

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/anas/storage/Elasticsearch-Exporter/exporter.js:9:11)
    at Module._compile (module.js:410:26)
    at Object.Module._extensions..js (module.js:417:10)

這是引發異常的行

exports.error = (...args) => !capture("ERROR", args) && console.log(timestamp() + util.format(...args).red);

我認為該錯誤與nodejs的不同版本有關,但我不確定。

這是node --version命令v4.2.6的輸出

這是npm --version命令3.10.6的輸出

是的,確實, ...被稱為傳播運算符 ,僅在Node.js 6之后可用

elasticsearch-exporter項目在其package.json文件中聲明它僅適用於節點版本> 6

因此,由於您正在運行Node.js 4.2.6,因此您需要升級Node.js安裝或派生elasticsearch-exporter項目並對其進行修改以與Node.js 4.2.6一起使用。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM