通过webpack意外令牌编译时出现此错误,预期为“,”

时间:2019-11-20 13:24:31

标签: reactjs redux react-redux redux-thunk redux-devtools-extension

在编译此代码时,出现此错误 SyntaxError:意外的令牌,预期为“,” 。我希望你能帮我这个忙。在线错误(13:39)

import { createStore, applyMiddleware } from 'redux';
import { composeWithDevTools } from 'redux-devtools-extension';
import thunk from 'redux-thunk';
import rootReducers from './reducers';

const initialState = {};

const middleware = [thunk];

const store = createStore({
    rootReducers,
    initialState,
    composeWithDevTools(applyMiddleware(...middleware))
});

export default store;

谢谢

1 个答案:

答案 0 :(得分:5)

您对createStore的呼叫是错误的。它应该是参数列表,而不是对象:

const store = createStore(rootReducers, initialState, composeWithDevTools(applyMiddleware(...middleware)));

正确的功能签名是:

 createStore(reducer, [preloadedState], [enhancer])

请参阅文档here