Browserify: Object spread fails with unexpected token

Created on 23 May 2017  路  2Comments  路  Source: browserify/browserify

spread/rest doesn't seem to work:

let foo = {somevar: 'test'}
let bar = {test: 'test'}
let baz = {...foo, ...bar}

browserify foo.js

foo.js:3
let baz = {...foo, ...bar}
           ^
ParseError: Unexpected token

Most helpful comment

Hi,

this issue is caused by underlying acorn parser which does not support this syntax feature currently.

Just now, you have tree choices how to solve this issue:

  • wait till acorn supports this syntax
  • patch acorn with https://github.com/UXtemple/acorn-object-spread
  • use this fork, which use babylon as the parser under the hood: https://github.com/zdychacek/node-browserify. And then run this command: $ browserify-babylon src/app.js -o dist/out.js -t [ babelify ] --parser-plugins [ objectRestSpread ]

All 2 comments

Hi,

this issue is caused by underlying acorn parser which does not support this syntax feature currently.

Just now, you have tree choices how to solve this issue:

  • wait till acorn supports this syntax
  • patch acorn with https://github.com/UXtemple/acorn-object-spread
  • use this fork, which use babylon as the parser under the hood: https://github.com/zdychacek/node-browserify. And then run this command: $ browserify-babylon src/app.js -o dist/out.js -t [ babelify ] --parser-plugins [ objectRestSpread ]
Was this page helpful?
0 / 5 - 0 ratings

Related issues

rkirsling picture rkirsling  路  6Comments

timwis picture timwis  路  4Comments

thlorenz picture thlorenz  路  5Comments

saeedseyfi picture saeedseyfi  路  6Comments

connor11528 picture connor11528  路  6Comments