ES6提供SyntaxError:意外令牌) [英] ES6 giving SyntaxError: Unexpected token )

查看:149
本文介绍了ES6提供SyntaxError:意外令牌)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这是我的Node.js脚本:

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

在Node.js v0.10.25(Ubuntu 2015.10上的默认设置)上执行时,我收到有关括号的语法错误:

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

我该如何解决?

推荐答案

Node 0.10中的V8版本不支持箭头功能.

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

您可以通过以下任一方法修复它:

You can fix it by either:

  • 使用类似Babel的代码将代码编译到ES5
  • 或者使用更新的Node版本,例如5.x
  • 使用箭头功能

(感谢James Allardice)

这篇关于ES6提供SyntaxError:意外令牌)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆