问题
I have a weird issue with, I guess, polyfills. I used MERN stack for my app, and pushed to Heroku. For some reason, on my computer in Chrome I can view the website, however, on other computers I'm getting a blank page and the error in console:
'SCRIPT5007: Unable to get property 'apply' of undefined or null reference'
it points to this chunk of code, and, apparently, is linked to Redux:
return funcs.reduce(function (a, b) {
return function () {
return a(b.apply(undefined, arguments));
};
});
}
I imported babel-polyfill to my App.js file, even added <script src="https://cdn.polyfill.io/v2/polyfill.min.js?features=default,es6"></script></script>
to index.html
but still no luck. What could be done to solve this?
UPD: It seems that the reason is the Redux Dev Tools. I need to somehow disable it in production.
回答1:
Apparently, the issue was linked with the Redux DevTools that I was using. So, in redux store.js I had to change this:
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(...middleware),
window._REDUX_DEVTOOLS_EXTENSION_ ? window.__REDUX_DEVTOOLS_EXTENSION__() // Error is this line
)
);
to this:
const store = createStore(
rootReducer,
initialState,
compose(
applyMiddleware(...middleware),
window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() : f => f
)
);
And everything worked.
来源:https://stackoverflow.com/questions/51388382/heroku-nodejs-and-react-issue-script5007-unable-to-get-property-apply-of-un