Reputation: 1773
I am having a lot of trouble rendering my react/redux app on my server. First I am requiring all the necessary babel libraries so the node server can recognize the syntax when reading the jsx files, but I still get syntax errors. The error I get is > 8 | return { ...state, check: true }; Unexpected token pointing at the ...
server.js
require('babel-register')({ presets: ['es2015', 'react'] });
require('import-export');
require('babel-polyfill');
const reducers = require('../src/reducers').default; //written with es6 import statements and export default
reducers
export default function(state = INITIAL, action) {
switch(action.type) {
case "CHECK":
return { ...state, check: true }; //error reading this line
default:
return state;
}
}
Upvotes: 0
Views: 163
Reputation: 972
The {...obj}
syntax is an ES7 feature named object-rest-spread
under babel, so the 2015/react presets don't include it. You'll have to add it to your babel config like "plugins": ["transform-object-rest-spread"]
More info on the babel site
Upvotes: 3