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

Ruh*_*ham 1 heroku node.js express reactjs mern

我猜我对polyfill有一个奇怪的问题。我为应用程序使用了MERN堆栈,然后推送到Heroku。由于某些原因,我可以在Chrome的计算机上查看该网站,但是,在其他计算机上却出现空白页和控制台错误:

'SCRIPT5007: Unable to get property 'apply' of undefined or null reference'
Run Code Online (Sandbox Code Playgroud)

它指向这段代码,并且显然链接到Redux:

return funcs.reduce(function (a, b) {
    return function () {
      return a(b.apply(undefined, arguments));
    };
  });
}
Run Code Online (Sandbox Code Playgroud)

我将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。我需要以某种方式在生产中禁用它。

Ruh*_*ham 7

显然,问题与我使用的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
  )
);
Run Code Online (Sandbox Code Playgroud)

对此:

const store = createStore(
  rootReducer,
  initialState,
  compose(
    applyMiddleware(...middleware),
    window.__REDUX_DEVTOOLS_EXTENSION__ ? window.__REDUX_DEVTOOLS_EXTENSION__ && window.__REDUX_DEVTOOLS_EXTENSION__() : f => f
  )
);
Run Code Online (Sandbox Code Playgroud)

一切正常。