2017-02-19 1 views
0

私のreact/reduxアプリケーションをサーバー上でレンダリングする際に問題がたくさんあります。まず、ノードサーバーがjsxファイルを読むときに構文を認識できるように、必要なすべてのライブラリを必要としていますが、構文エラーが表示されます。私が手にエラーが> 8 | return { ...state, check: true }; Unexpected token pointing at the ...私のノードサーバーは、babelライブラリがロードされていてもes6構文を認識することができません

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 

減速

export default function(state = INITIAL, action) { 
    switch(action.type) { 
    case "CHECK": 
     return { ...state, check: true }; //error reading this line 
    default: 
     return state; 
    } 
} 

答えて

3

{...obj}構文はバベルの下object-rest-spreadという名前ES7機能ですので、2015 /反応するプリセットが含まれていません。それ。あなたはon the babel site

+0

は私が必要(「バベル登録」)で私のプリセットに追加する必要はないでしょう"plugins": ["transform-object-rest-spread"]

詳細情報のようなあなたのバベルの設定に追加する必要がありますか? – joethemow

+0

これはあなたのプリセットの横にあります 'require( 'babel-register')(プリセット:['es2015'、 '反応']、プラグイン:['transform-object-rest-spread']}); ' –

+0

それは残りの広がりではない、それはes2015プリセットhttps://babeljs.io/docs/plugins/transform-es2015-spread/の一部である通常の広がりだ。 –

関連する問題