Paulos3000 Paulos3000 - 13 days ago 10
React JSX Question

Babel loader error: rest/spread operator not understood

When I try to run my webpack bundle, I get this console error:

BabelLoaderError: SyntaxError: Unexpected token (113:19)

111 |
112 | const render = () => ReactDOM.render(
> 113 | <TodoApp todos={...store.getState()}/>,
| ^
114 | document.getElementById("root")
115 | )
116 |


So the spread operator syntax is not understood. However, I have installed the babel-stage-2 preset which I have included in my loaders in
webpack.config.js
, as follows:

module: {
loaders: [
{
test: path.join(__dirname, 'public'),
loader: ['babel-loader'],
query: {
presets: debug ? ['react', 'es2015', 'react-hmre', 'stage-2'] : ['react', 'es2015', 'stage-2']
}
}
]
}


I also tried installing
babel-plugin-transform-object-rest-spread
and adding to
.babelrc
:

{
"plugins": ["transform-object-rest-spread"]
}


Still receiving the same error.

Any help appreciated!

Answer

Call {...store.getState()} instead of todos={...store.getState()}

Comments