Heroku, NodeJs and React issue: SCRIPT5007: Unable to get property 'apply' of undefined or null reference

时间秒杀一切 提交于 2020-02-24 12:16:17

问题


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

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!