2016-11-17 7 views
0

私は、React Developer ToolsのChrome拡張機能に自分のアプリを認識させようとしていますが、上記のエラーが発生しています。この問題に対処する最善の方法については、誰でも助言できますか?ReferenceError:ウィンドウが定義されていない(devToolsExtension)

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, 
 
);

答えて

2

あなたは万が一のサーバー側のレンダリングをやっていますか?ウィンドウが利用できない場合、私は、エラーを黙らせると考えることができ

一つクイックフィックスは、次のように別のチェックを追加することです:

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

はい、サーバー側のレンダリングが使用されています。 ReferenceError:Windowsが定義されていません がconfigureStore(C:/Users/d0475/Documents/Projects/proj/src/common/configureStore.js:30:6)にあります。 at req C:/ Users/d0475/Documents/Projects/proj/src/server/frontend/renderでC:/Users/d0475/Documents/Projects/proj/src/server/frontend/render.js:42:28) を実行してください。 js:109:19 – TheoG

+0

あなたのコードのどこか他の場所でウィンドウが参照されていますか?行全体を削除してもこのエラーが表示されますか? –

+0

いいえ、ウィンドウは別の場所では参照されていません。また、行が削除されてもエラーは表示されません。 – TheoG

関連する問題