Heroku、NodeJs 和 React 问题:SCRIPT5007:无法获取未定义或空引用的 属性 'apply'
Heroku, NodeJs and React issue: SCRIPT5007: Unable to get property 'apply' of undefined or null reference
我猜我有一个关于 polyfill 的奇怪问题。我为我的应用程序使用了 MERN 堆栈,并推送到 Heroku。出于某种原因,在 Chrome 我的计算机上我可以查看该网站,但是,在其他计算机上我得到一个空白页面并且控制台中出现错误:
'SCRIPT5007: Unable to get property 'apply' of undefined or null reference'
它指向这段代码,显然,链接到 Redux:
return funcs.reduce(function (a, b) {
return function () {
return a(b.apply(undefined, arguments));
};
});
}
我将 babel-polyfill 导入到我的 App.js 文件中,甚至将 <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,es6"></script></script>
添加到 index.html
但仍然没有成功。可以做些什么来解决这个问题?
UPD:看来是Redux Dev Tools的原因。我需要以某种方式在生产中禁用它。
显然,这个问题与我使用的 Redux DevTools 有关。所以,在 redux store.js 中我不得不改变这个:
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(...middleware),
window._REDUX_DEVTOOLS_EXTENSION_ ? window.__REDUX_DEVTOOLS_EXTENSION__() // Error is this line
)
);
对此:
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(...middleware),
window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() : f => f
)
);
一切正常。
我猜我有一个关于 polyfill 的奇怪问题。我为我的应用程序使用了 MERN 堆栈,并推送到 Heroku。出于某种原因,在 Chrome 我的计算机上我可以查看该网站,但是,在其他计算机上我得到一个空白页面并且控制台中出现错误:
'SCRIPT5007: Unable to get property 'apply' of undefined or null reference'
它指向这段代码,显然,链接到 Redux:
return funcs.reduce(function (a, b) {
return function () {
return a(b.apply(undefined, arguments));
};
});
}
我将 babel-polyfill 导入到我的 App.js 文件中,甚至将 <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,es6"></script></script>
添加到 index.html
但仍然没有成功。可以做些什么来解决这个问题?
UPD:看来是Redux Dev Tools的原因。我需要以某种方式在生产中禁用它。
显然,这个问题与我使用的 Redux DevTools 有关。所以,在 redux store.js 中我不得不改变这个:
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(...middleware),
window._REDUX_DEVTOOLS_EXTENSION_ ? window.__REDUX_DEVTOOLS_EXTENSION__() // Error is this line
)
);
对此:
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(...middleware),
window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() : f => f
)
);
一切正常。