Search code examples
javascriptreactjsecmascript-6browserifyfixed-data-table

"Uncaught SyntaxError: Unexpected token { " using Reactify


I am following a tutorial to create a FixedDataTable with React. However, I have some issues getting the following line to work in my jsx-file:

const {Table, Column, Cell} = require('fixed-data-table');

which gives the error (in Chrome):

Uncaught SyntaxError: Unexpected token {

I am using browserify and reactify to transform my jsx code to javascript. Other lines using require work fine.

I am quite new to JavaScript and React and would appreciate any suggestions to solve hte problem.


Solution

  • The issue was as pointed out in the comments that the ES6 option in reactify wasn't activated. I edited the following row in my gulpfile:

    transform: [
        [ 'reactify', {'es6': true} ]
    ],
    

    And then it worked. As a workaround I found out that you also can do:

    var FixedDataTable = require('fixed-data-table');
    
    var Table = FixedDataTable.Table;
    
    var Column = FixedDataTable.Column;
    

    instead of

    var {Table, Column, Cell} = require('fixed-data-table');