ReferenceError:未定义窗口(devToolsExtension)

时间:2016-11-17 17:51:35

标签: reactjs

所以,我试图让'React Developer Tools'的Chrome扩展程序知道我的应用程序,但是我收到了上面提到的错误。有人可以就解决这个问题的最佳方法提出建议吗?

import configureMiddleware from './configureMiddleware';
import configureReducer from './configureReducer';
import configureStorage from './configureStorage';
import { applyMiddleware, createStore, compose } from 'redux';
import { persistStore, autoRehydrate } from 'redux-persist';

type Options = {
  initialState: Object,
  platformDeps?: Object,
  platformMiddleware?: Array<Function>,
};

const configureStore = (options: Options) => {
  const {
    initialState,
    platformDeps = {},
    platformMiddleware = [],
  } = options;

  const reducer = configureReducer(initialState);

  const middleware = configureMiddleware(
    initialState,
    platformDeps,
    platformMiddleware,
  );

  const enhancers = compose(
    window.devToolsExtension ? window.devToolsExtension() : f => f
  );

  const store = createStore(
    reducer,
    initialState,
    compose(
      applyMiddleware(...middleware),
      autoRehydrate(),
    ),
    enhancers,
  );

1 个答案:

答案 0 :(得分:2)

您是否正在进行服务器端渲染?

我可以想到的一个快速解决方法是在窗口不可用时使错误静音是添加另一个检查,如下所示:

const enhancers = compose(
 (typeof window !== 'undefined' && window.devToolsExtension) ? window.devToolsExtension() : f => f
);