TypeError:从Redux使用连接时_this.store.getState不是函数

当我第一次运行服务器node app.js一切都很好,我listening on 5050然后我去localhost:5050 /,我得到这些警告在服务器运行的控制台。

 Warning: Failed propType: Required prop `store.subscribe` was not specified in `Provider`. Warning: Failed Context Types: Required child context `store.subscribe` was not specified in `Provider`. 

该组件呈现罚款那里,但一旦我去本地主机:5050 / ballerviews我得到这个在服务器上

 TypeError: _this.store.getState is not a function at new Connect (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react-redux/lib/components/connect.js:133:38) at [object Object].ReactCompositeComponentMixin.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactCompositeComponent.js:148:18) at [object Object].wrapper [as mountComponent] (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactPerf.js:66:21) at Object.ReactReconciler.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactReconciler.js:37:35) at ReactDOMComponent.ReactMultiChild.Mixin.mountChildren (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactMultiChild.js:241:44) at ReactDOMComponent.Mixin._createContentMarkup (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactDOMComponent.js:591:32) at ReactDOMComponent.Mixin.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactDOMComponent.js:479:29) at Object.ReactReconciler.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactReconciler.js:37:35) at [object Object].ReactCompositeComponentMixin.mountComponent (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactCompositeComponent.js:225:34) at [object Object].wrapper [as mountComponent] (/Users/freddiecabrera/Desktop/ullibol-client/node_modules/react/lib/ReactPerf.js:66:21) 

你可以在我的Github上查看完整的项目,因为我觉得在那里你可以得到最好的理解。

我一直试图弄清楚这一整天,我不能。 在我尝试在服务器上呈现之前,它工作正常。 我感谢您的帮助,如果您需要更多的信息来回答这个问题,请让我知道。

只有两个小问题:

1. ES2015模块 – > CommonJS

您在src/store.js中使用了ES2015 export default ,但是您需要通过#11上的app.js CommonJS来获取它。

这当然是好的,但是当你需要的时候你会想要访问默认的属性。 更新行如下:

 // Old const store = require('./src/store.js') // New const store = require('./src/store.js').default 

2.在服务器上调用document

src/components/BallerViews.jsx #41行上 ,您正在访问文档,该文档在服务器上不存在。 一个快速的解决办法是将该行包含在条件中:

 // Old document.body.style.backgroundColor = '#0e0e13' // New if (typeof document !== 'undefined') { document.body.style.backgroundColor = '#0e0e13' }