最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - NodeJS (ES6): SyntaxError: Unexpected token { - Stack Overflow

programmeradmin2浏览0评论
let {name, description} = req.body;

NodeJS v5.2.0. Tried using flags - node bin/www --es_staging --harmony_destructuring. Throws an error: SyntaxError: Unexpected token {... Should I pile source using Babel, or is there any other way to use ES6 natively in NodeJS?

let {name, description} = req.body;

NodeJS v5.2.0. Tried using flags - node bin/www --es_staging --harmony_destructuring. Throws an error: SyntaxError: Unexpected token {... Should I pile source using Babel, or is there any other way to use ES6 natively in NodeJS?

Share Improve this question asked Dec 19, 2015 at 16:45 Ramziddin MakhmudovRamziddin Makhmudov 1142 silver badges9 bronze badges 2
  • 1 I think this isn't supported yet on Node 5.0. Babel does seem to support that according to this – MinusFour Commented Dec 19, 2015 at 16:52
  • 1 I remend to read the official documentation, which would have answered your question: nodejs/en/docs/es6 – Felix Kling Commented Dec 19, 2015 at 17:56
Add a ment  | 

1 Answer 1

Reset to default 9

Destructuring assigments are not supported by default in Node 5.2.0, but it will work if you enable it with node --harmony_destructuring.

However let is only supported in strict mode for now.
This is a V8 issue, and Node version 5.0.0, which will include V8 version 4.6 will also support let in sloppy mode.

Using let in sloppy mode at the moment, will throw the exact same error you're getting, so :

"use strict"

let {name, description} = {name: "some name", description : "some description"};

works fine in Node 5.2.0, note that the object, in your case req.body, must have the same keys as the variable names, otherwise they'll be undefined.

发布评论

评论列表(0)

  1. 暂无评论