Heroku,NodeJs和React问题:SCRIPT5007:无法获取未定义或空引用的属性“apply”

问题描述 投票:0回答:1

我想,我有一个奇怪的问题,即polyfills。我使用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。我需要以某种方式在生产中禁用它。

node.js reactjs express heroku mern
1个回答
6
投票

显然,这个问题与我正在使用的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
  )
);

一切顺利。

© www.soinside.com 2019 - 2024. All rights reserved.