ES6 giving SyntaxError: Unexpected token ) [duplicate]

风格不统一 提交于 2019-12-12 01:37:40

问题


Here is my Node.js script:

pDownload("http://serv/file", "localfile")
  .then( ()=> console.log('downloaded file no issues...'))
  .catch( e => console.error('error while downloading', e));

function pDownload(url, dest){} // Yes empty, for now

When executing on Node.js v0.10.25 (default on Ubuntu 2015.10) I receive this syntax error about the parenthesis:

/home/nico/main.js:2
  .then( ()=> console.log('downloaded file no issues...'))
          ^
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 Function.Module.runMain (module.js:497:10)
    at startup (node.js:119:16)
    at node.js:902:3

How can I fix it?


回答1:


The version of V8 in Node 0.10 doesn't support arrow functions.

You can fix it by either:

  • Using something like Babel to compile your code to ES5
  • Or using a more recent version of Node, like 5.x
  • Doing with arrow functions

(Thanks James Allardice)



来源:https://stackoverflow.com/questions/35312609/es6-giving-syntaxerror-unexpected-token

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!