kirill-konshin / next-redux-wrapper

Redux wrapper for Next.js
MIT License
2.67k stars 265 forks source link

Production only : 'Could not find "store" in the context of "Connect(...)"." #131

Closed lucasriondel closed 5 years ago

lucasriondel commented 5 years ago

My app is running perfectly in development mode. During build, everything's fine, but when I npm start my app, I have nothing but an Internal Server Error and errors.

Here's the code:

import withRedux from 'next-redux-wrapper'
import App, { Container } from 'next/app'
import React from 'react'
import { Provider } from 'react-redux'
import { Store } from 'redux'
import 'sanitize.css'
import AppContentWrapper from '../components/AppContentWrapper/AppContentWrapper'
import redux, { IRootState } from '../redux'
import './app.module.scss'

interface IProps {
  store: Store<IRootState>
}

class MyApp extends App<IProps> {
  public render() {
    const { Component, pageProps, store } = this.props

    return (
      <Container>
        <Provider store={store}>
          <AppContentWrapper Component={Component} pageProps={pageProps} />
        </Provider>
      </Container>
    )
  }
}

export default withRedux(redux, { debug: true })(MyApp)

And the error's when i'm trying to access my app:

1. WrappedApp.getInitialProps wrapper got the store with state { **my initialState** }

3. WrappedApp.getInitialProps has store state { **my initialState** }

4. WrappedApp.render created new store with initialState { **my initialState** }

{ Invariant Violation: Could not find "store" in the context of "Connect(HeadBand)". Either wrap the root component in a <Proider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(HeadBand in connect options.
    at invariant (C:\pathToProject\front\node_modules\invariant\invariant.js:40:15)
    at Connect.renderWrappedComponent (C:\pathToProject\front\node_modules\react-redux\lib\compoents\connectAdvanced.js:172:32)
    at Connect.indirectRenderWrappedComponent (C:\pathToProject\front\node_modules\react-redux\lb\components\connectAdvanced.js:168:21)
    at a.render (C:\pathToProject\front\node_modules\react-dom\cjs\react-dom-server.node.producton.min.js:44:64)
    at a.read (C:\pathToProject\front\node_modules\react-dom\cjs\react-dom-server.node.productio.min.js:41:58)    at renderToString (C:\pathToProject\front\node_modules\react-dom\cjs\react-dom-server.node.pe.production.min.js:53:83)
    at render (C:\pathToProject\front\node_modules\next-server\dist\server\render.js:86:16)
    at renderPage (C:\pathToProject\front\node_modules\next-server\dist\server\render.js:211:20)    at Function.value (C:\pathToProject\front\.next\server\static\NFnkV1BN6T6f7D675dZk7\pages\_document.js:812:41)    at Object.loadGetInitialProps (C:\pathToProject\front\node_modules\next-server\dist\lib\utils.js:42:35) name: 'Invariant Violation', framesToPop: 1 }

1. WrappedApp.getInitialProps wrapper got the store with state { **my initialState** }

3. WrappedApp.getInitialProps has store state { **my initialState** }

4. WrappedApp.render created new store with initialState { **my initialState** }

{ Invariant Violation: Could not find "store" in the context of "Connect(ContactFormComponent)". Either wrap the root component in a <Provider>, or pass a custom React context provider to <Provider> and the corresponding React context consumer to Connect(ContactFormComponent) in connect options.
    at invariant (C:\pathToProject\front\node_modules\invariant\invariant.js:40:15)
    at Connect.renderWrappedComponent (C:\pathToProject\front\node_modules\react-redux\lib\components\connectAdvanced.js:172:32)
    at Connect.indirectRenderWrappedComponent (C:\pathToProject\front\node_modules\react-redux\lib\components\connectAdvanced.js:168:21)
    at a.render (C:\pathToProject\front\node_modules\react-dom\cjs\react-dom-server.node.production.min.js:44:64)
        at a.read (C:\pathToProject\front\node_modules\react-dom\cjs\react-dom-server.node.production.min.js:41:58)
        at renderToString (C:\pathToProject\front\node_modules\react-dom\cjs\react-dom-server.node.production.min.js:53:83)
        at render (C:\pathToProject\front\node_modules\next-server\dist\server\render.js:86:16)
        at renderPage (C:\pathToProject\front\node_modules\next-server\dist\server\render.js:211:20)
        at Function.value (C:\pathToProject\front\.next\server\static\NFnkV1BN6T6f7D675dZk7\pages\_document.js:812:41)
        at Object.loadGetInitialProps (C:\pathToProject\front\node_modules\next-server\dist\lib\utils.js:42:35) name: 'Invariant Violation', framesToPop: 1 }

next 8.1.0, next-redux-wrapper 3.0.0-alpha.2

kirill-konshin commented 5 years ago

Need a repo to reproduce the issue.

kirill-konshin commented 5 years ago

I cannot reproduce the issue using the demo supplied in this repository...

kirill-konshin commented 5 years ago

Closing due to inactivity.